2012-12-11 90 views
2

我们建立了一个ASP.Net GridView,并包含排序和分页。当用户单击GridView列标题链接以排序数据时,或者如果用户单击GridView底部的数字链接以分页数据,则不会发生任何事情。使用ASP.Net GridView排序和分页

这里是标记为GridView的削减版本:

<asp:UpdatePanel 
    ID="UpdatePanelSummary" 
    runat="server" 
    UpdateMode="Always"> 

    <ContentTemplate> 

     <h1>Maintenance</h1> 

     <% '-- GridView (Grid) for summary.              -- %> 
     <% '-- The user chooses a summary row from here and details are shown in a DetailsView. -- %> 
     <% '--------------------------------------------------------------------------------------- %> 

     <asp:GridView 
      ID="GridViewSummary" 
      runat="server" 
      AllowSorting="True" 
      AutoGenerateColumns="False" 
      DataKeyNames="ID" 
      Width="224px" 
      AllowPaging="True" 
      PageSize="7"> 

      <Columns> 
       <asp:BoundField DataField="Unit" HeaderText="Unit" 
        SortExpression="Unit" /> 

       <asp:BoundField DataField="TheName" HeaderText="Name" 
        SortExpression="TheName" /> 

       <asp:BoundField DataField="ID" 
        HeaderText="ID" SortExpression="ID" InsertVisible="False" ReadOnly="True" 
        Visible="False" /> 

       <asp:CommandField ButtonType="Button" SelectText="Select Unit Details" 
        ShowSelectButton="True" /> 
      </Columns> 
     </asp:GridView> 
    </ContentTemplate> 
</asp:UpdatePanel> 

由于什么也没发生,我们假设我们需要写一些代码在代码隐藏文件。你能告诉我们什么编码需要唤醒排序和分页?

+0

什么是您的DataSource?你也在UpdatePanel中。当部分页面呈现请求中抛出异常时,UpdatePanel的行为会很奇怪。你可以删除UpdatePanel进行调试,看看你的代码隐藏是否会引发异常? – Carsten

+0

数据源是从使用VB.Net代码隐藏文件内设置:昏暗theTableAdapter作为新DataSetClassesTableAdapters.ClassesTableAdapter 私人小组Teachers_Init(发送者为对象,例如作为EventArgs的)把手Me.Init '加载从数据数据库导入到GridView中。 '------------------------------------------------ --- GridViewSummary.DataSource = theTableAdapter.GetDataByAllClasses GridViewSummary.DataBind() 结束子 –

+0

我除去在UpdatePanel并且显示这个错误:GridView的 'GridViewSummary' 激发事件PageIndexChanging这是不处理的。我将添加Bonny Bonev建议的编码,因为它使用该事件处理程序。 –

回答

2

退房这个职位 sorting and paging with gridview asp.net

基本上你需要添加服务器端事件处理程序进行排序和分页。

下面是一个示例 - 您可以复制/粘贴大部分内容。

http://www.dotnetspider.com/resources/1249-Grid-View-Paging-Sorting.aspx

+0

感谢您的快速回复。我会看看它。 –

+0

感谢您的补充。我会尝试将其转换为VB.Net,并让你知道我们是否可以使它工作。 –

+0

得到分页工作。现在我将着手分类。再次感谢。 :-) –