GridView RowDeleting event is not working?

Started on the old forum in October 2010 · view the original in the archive · old links redirect here

No replies · 1,200 views · started 16 years ago · 1 min read

poojashah623 Newbie · 5 posts #1

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.

Write your reply now; next you create a free account (or sign in) and it is posted right away. Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close