Click here to Skip to main content
15,898,538 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have the below gridviews:

ASP
<asp:GridView runat="server" ID="GridView2" OnRowDataBound="gvChildGrid_RowDataBound"  Width="1000px"
        DataKeyNames="number"   AllowSorting="false" style="font-size:15px;"
        AutoGenerateColumns="False" BackColor="White" BorderColor="#E7E7FF" AllowPaging="true" HorizontalAlign="Center"
        CellPadding="4" GridLines="none">
        <%-- <PagerSettings Mode="NumericFirstLast" FirstPageText="first" PreviousPageText="previous" LastPageText="last" NextPageText="next" Position="bottom" PageButtonCount="2" />--%>
        <AlternatingRowStyle BackColor="#F7F7F7" />
        <Columns>
        <asp:TemplateField HeaderText = "Select">
        <ItemTemplate>
        <a href="JavaScript:divexpandcollapse('div<%# Eval("number") %>');">
        <img id="imgdiv" width = "20px" src="images/Alarm-Plus-icon.png" alt="" />
        </a>
        </ItemTemplate>
        <HeaderStyle Font-Bold="True"/>
        </asp:TemplateField>

        <asp:TemplateField HeaderText = "Number">
        <ItemTemplate>
        <%# Eval("number")%>
        </ItemTemplate>
        </asp:TemplateField>


        <asp:TemplateField HeaderText = "Name">
        <ItemTemplate>
        <%# Eval("name")%>
        </ItemTemplate>
        </asp:TemplateField>


        <asp:TemplateField>
        <ItemTemplate>
        <tr>
        <td colspan="100%">
        <div id="div<%# Eval("number") %>" style="display: none; position: relative;  overflow: auto">
        <asp:GridView ID="gvChildGrid"  runat="server" BackColor="Transparent" AutoGenerateColumns="false"
        style="Width:100% !important;"  GridLines="None"  Font-Names="times new roman" AllowPaging="True" CellPadding="4"  AllowSorting="True">
        <HeaderStyle BackColor="#8cc63e" Font-Bold="true" ForeColor="White" />
        <Columns>
        <asp:BoundField DataField="number"  HeaderText="Mobile Number" >
        <ItemStyle HorizontalAlign="Center" />
        </asp:BoundField>
        <asp:BoundField DataField="name"  HeaderText="Name" >
        <ItemStyle HorizontalAlign="Center"  />
        </asp:BoundField>
        </Columns>
        </asp:GridView>
        </div>
        </td>
        </tr>
        </ItemTemplate>
        </asp:TemplateField>


        </Columns>
        </asp:GridView>

i have a gridview gvChildGrid that is in a parent gridview GridView2

i need to code the page indexing of the child gridview gvChildGrid but i'm not being able to catch the event from the behind code... because from the code i'm not able to get the id of the gridview gvChildGrid

i need to write the below but i keep getting that gvChildGrid is not a declared
VB
  Protected Sub gvChildGrid_PageIndexChanging(sender As Object, e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles gvChildGrid.PageIndexChanging
    gvChildGrid.PageIndex = e.NewPageIndex
    gvChildGrid.DataSource = x.searchByName(TextBox1.Text)
    gvChildGrid.DataBind()
End Sub

so if i need to read the gridview i have to read it as below :

Dim gv As GridView = DirectCast(e.Row.FindControl("gvChildGrid"), GridView)
but in this case what should be the event? i need the event on the pageindexing of this gridview

any advices?
Posted

Hook the event up from the markup rather than the code-behind:
VB.NET
Protected Sub gvChildGrid_PageIndexChanging(sender As Object, e As GridViewPageEventArgs) 'NB: No "Handles" clause here
    Dim gvChildGrid As GridView = DirectCast(sender, GridView)
    ...

aspx
<asp:GridView ID="gvChildGrid" runat="server" ... OnPageIndexChanging="gvChildGrid_PageIndexChanging">
 
Share this answer
 
Comments
Jocelyne El Khoury 2-Jul-14 8:36am    
okey done but how can i prevent the page to post back and return to page load?
set the OnPageIndexChanging as below
<asp:GridView ID="gvChildGrid"  runat="server OnPageIndexChanging="gvChildGrid_PageIndexChanging" runat="server"

check below articles which may help you.
Collapsible Nested GridView with Paging using ASP.Net[^]
Editable Nested GridView (All-in-One)[^]
 
Share this answer
 
v3

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