网格视图中的网格视图的页面索引 [英] page indexing of a gridview that is in a gridview

查看:98
本文介绍了网格视图中的网格视图的页面索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下网格视图:



i have the below gridviews:

<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有一个gridview gvChildGrid,它在父网格中GridView2



i需要编写子gridview gvChildGrid的页面索引编码但是我无法从后面的代码中捕获事件...因为从代码中我无法获得gridview的id gvChildGrid



i需要写下面但我一直认为gvChildGrid不是声明的


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

  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



所以,如果我需要阅读gridview,我必须阅读如下:



Dim gv As GridView = DirectCast(e.Row.FindControl(gvChildGrid),GridView)

但在这种情况下是什么应该是活动?我需要在这个gridview的pageindexing上的事件



任何建议?


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?

推荐答案

将事件挂起从标记而不是代码隐藏:

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




<asp:GridView ID="gvChildGrid" runat="server" ... OnPageIndexChanging="gvChildGrid_PageIndexChanging">


将OnPageIndexChanging设置如下

set the OnPageIndexChanging as below
<asp:GridView ID="gvChildGrid"  runat="server OnPageIndexChanging="gvChildGrid_PageIndexChanging" runat="server"



查看以下可能对您有帮助的文章。

使用ASP.Net进行分页的可折叠嵌套GridView [ ^ ]

可编辑嵌套GridView(多功能一体机) [ ^ ]


这篇关于网格视图中的网格视图的页面索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆