Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3501128
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T12:49:13+00:00 2026-05-18T12:49:13+00:00

I have come across odd behavior involving nested gridview controls and row events. Basically

  • 0

I have come across odd behavior involving nested gridview controls and row events. Basically the nested gridview row event will not fire unless it is in the last row of the outer grid.

If you explicitly add the row event property to the markup (e.g. OnRowDeleted=”gvInner_RowDeleted”) then the row event fires for all nested gridviews however it fires twice for the nested gridview in the last row of the outer gridview

EDIT: I should note that I am using the SqlDataSource for the outer gridview as it is also editable. This isn’t clear in the example.

Markup:

<asp:GridView ID="gvOuter" DataSourceID="sdsOuter" runat="server" OnRowDatabound="DynamicControlAdder" AutoGenerateColumns="false">
    <Columns>
        <asp:BoundField DataField="Id" ReadOnly="true" />
        <asp:TemplateField>
            <ItemTemplate>        

                        <asp:UpdatePanel ID="upInner" runat="server" UpdateMode="Conditional">
                            <ContentTemplate>                                
                                <asp:GridView ID="gvInner" DataSourceId="sdsInner" runat="server" DataKeyNames="Id"  AutoGenerateColumns="false">
                                    <Columns>
                                        <asp:CommandField ShowDeleteButton="true" />
                                        <asp:BoundField DataField="Id" />                                            
                                    </Columns>
                                </asp:GridView>
                                <asp:SqlDataSource ID="sdsInner" runat="server" 
                                    ProviderName="<%$ ConnectionStrings:YourString.ProviderName %>" 
                                    ConnectionString="<%$ ConnectionStrings:YourString %>"
                                    SelectCommand="SELECT * FROM tblInner WHERE OuterTableKey = @OuterTableKey"
                                    DeleteCommand="DELETE FROM tblInner WHERE Id = @Id">
                                    <SelectParameters>
                                        <asp:Parameter Name="OuterTableKey" DefaultValue="0" Type="Int32" />
                                    </SelectParameters>
                                    <DeleteParameters>
                                        <asp:Parameter Name="Id" DefaultValue="0" Type="Int32" />                                            
                                    </DeleteParameters>                                        
                                </asp:SqlDataSource>                                                 
                            </ContentTemplate>                
                        </asp:UpdatePanel>    

            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>
<asp:SqlDataSource ID="sdsOuter" runat="server"
   ProviderName="<%$ ConnectionStrings:YourString.ProviderName %>" 
   ConnectionString="<%$ ConnectionStrings:YourString %>"
   SelectCommand="SELECT * FROM tblOuter">                                        
</asp:SqlDataSource>

Code:

Partial Class Testing
Inherits System.Web.UI.UserControl

Protected Sub DynamicControlAdder(ByVal sender As Object, ByVal e As GridViewRowEventArgs)

    If e.Row.RowType <> DataControlRowType.DataRow Then
        Exit Sub
    End If

    Dim s As SqlDataSource = CType(e.Row.FindControl("sdsInner"), SqlDataSource)
    s.SelectParameters("OuterTableKey").DefaultValue = e.Row.DataItem("Id").ToString()

End Sub

Protected Sub gvInner_RowDeleted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeletedEventArgs) Handles gvInner.RowDeleted
    //'This never fires unless it is the last row in the outer gridview
    //'also, if this event is declared in the OnRowDeleted property of the inner gridview, this event fires twice if it is in the last row of the outer grid
    Dim strFoo As String = "Foo"
End Sub
End Class

Can anybody reproduce this, and how do you work around it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T12:49:14+00:00Added an answer on May 18, 2026 at 12:49 pm

    And the answer is……

    Remove the handles clause from the RowDeleted Event and set the OnRowDeleted Property to the gvInner_RowDeleted event.

    Updated code below. I just wish i had the last 4 hours of my life back.

    Markup:

    <asp:GridView ID="gvOuter" DataSourceID="sdsOuter" runat="server" OnRowDatabound="DynamicControlAdder" AutoGenerateColumns="false">
        <Columns>
            <asp:BoundField DataField="Id" ReadOnly="true" />
            <asp:TemplateField>
                <ItemTemplate>        
    
                            <asp:UpdatePanel ID="upInner" runat="server" UpdateMode="Conditional">
                                <ContentTemplate>                                
                                    <asp:GridView ID="gvInner" DataSourceId="sdsInner" runat="server" DataKeyNames="Id" OnRowDeleted="gvInner_RowDeleted"  AutoGenerateColumns="false">
                                        <Columns>
                                            <asp:CommandField ShowDeleteButton="true" />
                                            <asp:BoundField DataField="Id" />                                            
                                        </Columns>
                                    </asp:GridView>
                                    <asp:SqlDataSource ID="sdsInner" runat="server" 
                                        ProviderName="<%$ ConnectionStrings:YourString.ProviderName %>" 
                                        ConnectionString="<%$ ConnectionStrings:YourString %>"
                                        SelectCommand="SELECT * FROM tblInner WHERE OuterTableKey = @OuterTableKey"
                                        DeleteCommand="DELETE FROM tblInner WHERE Id = @Id">
                                        <SelectParameters>
                                            <asp:Parameter Name="OuterTableKey" DefaultValue="0" Type="Int32" />
                                        </SelectParameters>
                                        <DeleteParameters>
                                            <asp:Parameter Name="Id" DefaultValue="0" Type="Int32" />                                            
                                        </DeleteParameters>                                        
                                    </asp:SqlDataSource>                                                 
                                </ContentTemplate>                
                            </asp:UpdatePanel>    
    
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
    <asp:SqlDataSource ID="sdsOuter" runat="server"
       ProviderName="<%$ ConnectionStrings:YourString.ProviderName %>" 
       ConnectionString="<%$ ConnectionStrings:YourString %>"
       SelectCommand="SELECT * FROM tblOuter">                                        
    </asp:SqlDataSource>
    

    Code:

    Partial Class Testing
    Inherits System.Web.UI.UserControl
    
    Protected Sub DynamicControlAdder(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
    
        If e.Row.RowType <> DataControlRowType.DataRow Then
            Exit Sub
        End If
    
        Dim s As SqlDataSource = CType(e.Row.FindControl("sdsInner"), SqlDataSource)
        s.SelectParameters("OuterTableKey").DefaultValue = e.Row.DataItem("Id").ToString()
    
    End Sub
    
    Protected Sub gvInner_RowDeleted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeletedEventArgs) 
        //' Now we're talking
        Dim strFoo As String = "Foo"
    End Sub
    End Class
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have come across a strange behavior of Java that seems like a bug.
I have come across a very odd problem in C that I have never
I've come across an odd scenario in which window.open() is not triggering the 'load'
This is an odd one, not one I've come across before. My project complies
I have come across a lot of optimization tips which say that you should
I have come across the following type of code many a times, and I
I have come across what must be a common problem. When I have an
I have come across a quirky feature in Visual Studio and I was interested
In my work I have come across syntax like global:: (C#) or G:Loading($value) in
One of the problems I have come across having complex tasks on the browser

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.