GridView RowDeleting event is not working?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    GridView RowDeleting event is not working?

    I have made autogenerateeditbutton and deletebutton to true. I want to do is to delete the record when i press the delete link button.
    My code is here:

    <asp:GridView ID="TblUserGrid" runat="server" AllowPaging="True"
    AutoGenerateColumns="False" BackColor="White" BorderColor="#CCCCCC"
    BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Horizontal"
    onpageindexchanging="TblUserGrid_PageIndexChanging " PageSize="5" Width="424px"
    onrowediting="TblUserGrid_RowEditing1" AutoGenerateDeleteButton="True"
    AutoGenerateEditButton="True"
    onrowcancelingedit="TblUserGrid_RowCancelingEdit"
    onrowupdating="TblUserGrid_RowUpdating" onrowdeleting="TblUserGrid_RowDeleting"
    >
    <RowStyle ForeColor="#000066" />

    <Columns>
    <asp:TemplateField HeaderText="Name">
    <ItemTemplate>
    <%#Eval("Name") %>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:TextBox ID="TextBox1" runat="server" Text='<%#Eval("Name") %>'></asp:TextBox>
    </EditItemTemplate>
    </asp:TemplateField>

    <asp:TemplateField HeaderText="UserName">
    <ItemTemplate><%#Eval("login") %></ItemTemplate>
    <EditItemTemplate>
    <asp:Label ID="Label1" runat="server" Text='<%#Eval("login") %>'></asp:Label>
    </EditItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Password">
    <ItemTemplate><%#Eval("pass") %></ItemTemplate>
    <EditItemTemplate>
    <asp:TextBox ID="TextBox2" runat="server" Text='<%#Eval("pass") %>'></asp:TextBox>
    </EditItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Type">
    <ItemTemplate><%#Eval("usertype") %></ItemTemplate>
    <EditItemTemplate>
    <asp:TextBox ID="TextBox3" runat="server" Text='<%#Eval("usertype") %>'></asp:TextBox>
    </EditItemTemplate>
    </asp:TemplateField>

    </Columns>

    <FooterStyle BackColor="White" ForeColor="#000066" />
    <PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />

    <SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
    <HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
    </asp:GridView>

    This the code written for deleting row from grid bt its not working.
    My problem is that i not getting the value in the "lbl", its giving me null. Bcoz of that its giving me error of "object reference to set to an instance.On that row the value is there,still its giving me error.

    protected void TblUserGrid_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
    GridViewRow row = (GridViewRow)TblUserGrid.Rows[e.RowIndex];
    Label lbl = (Label)row.FindControl("Label1");
    conn.DeleteRow(lbl.Text );
    LoadTable();
    }

    Pls help me...
    Thnxs in advance.
Working...
X