Click here to Skip to main content
15,921,174 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello every one;
i have a gridview that is never postback after hitting delete linkButton, it just renders after reload the page or adding a new row to it. also I've a confirm message user control that should be popped up after hitting delete and does not show up.
this is a code snippet:
ASP.NET
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4"
                                        DataSourceID="ObjectDataSource1" ForeColor="#333333" GridLines="None" meta:resourcekey="GridView1Resource1"
                                        OnSelectedIndexChanged="GridView1_SelectedIndexChanged" OnRowEditing="GridView1_RowUpdating">
                                        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                                        <!-- some columns-->
<ItemTemplate>
                                                    <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Edit"
                                                        Text="Delete" meta:resourcekey="BoundFieldResource144"></asp:LinkButton>
                                                </ItemTemplate>
                                            </asp:TemplateField>
<!--user control-->
   <uc5:MessageBoxConfirm  runat="server" ID="MessageBoxCon"   ButtonNoText="No" ButtonYesText="Yes" />

the code behinde:
C#
protected void GridView1_RowDeleting(object sender, GridViewEditEventArgs e)
  {
      try
      {

        MessageBoxCon.ShowBox(CommonRes.Delete,CommonRes.AreYouSureThatYouWantToDelete, CommonRes.Yes, CommonRes.No);//user control

                 int count = Convert.ToInt32(e.NewEditIndex);
          List<classname> clrList = new List<classname>();
          clsList = (List<classname>)Session["SaveList"];

          classname clsnm = new classname();
          clsnm  = clrList.ElementAt(count);

          clsList.Remove(clsnm );
          Session["SaveList"] = clsList;

      }
      catch (Exception ex)
      {

      }

  }
protected void MessageBoxConfirm_Confirm(object sender,EventArgs e)
  {

  }

  protected void MessageBoxConfirm_Cancel(object sender, EventArgs e)
  {

  }
Posted

1 solution

First of all, you have not defined the event in Markup.

Refer - GridView.RowDeleting Event[^]. See how it is defined in the example.
HTML
<asp:GridView ID="CustomersGridView" runat="server"
        DataSourceID="CustomersSqlDataSource"
        AutoGenerateColumns="False"
        AutoGenerateDeleteButton="True"
        OnRowDeleting="CustomersGridView_RowDeleting"
        DataKeyNames="CustomerID,AddressID">

And here it automatically shows Delete button, as a result of that, the event gets fired automatically when you click on that.

But if you want to use LinkButton, then you need to implement differently either with
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900