【问题标题】:Gridview not working on PageIndexChangingGridview 在 PageIndexChanging 上不起作用
【发布时间】:2012-12-05 12:04:30
【问题描述】:

我正在使用没有数据源的 gridview。在PageIndexChanging 页面是空白的。

我的后端代码是:

protected void gridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    Gen_Lic_Grid.PageIndex = e.NewPageIndex;
    Gen_Lic_Grid.DataBind();
}

我的前端代码是:

  <asp:GridView ID="Gen_Lic_Grid" runat="server" AllowPaging="True" AutoGenerateColumns="False" CellPadding="4" DataKeyNames="Lic_No" ForeColor="#333333" GridLines="None" OnPageIndexChanging="gridView_PageIndexChanging" PageSize="15" Width="110%">
   <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
    <Columns>
 <asp:BoundField DataField="Lic_No" HeaderText="License No" ReadOnly="True" SortExpression="Lic_No" />
 <asp:BoundField DataField="UserID" HeaderText="User ID" SortExpression="UserID" />
 <asp:BoundField DataField="Org" HeaderText="Organization" 
                                    SortExpression="Org" />
 <asp:BoundField DataField="UserName" HeaderText="User Name" SortExpression="UserName" />
 <asp:BoundField DataField="SolType" HeaderText="Solution Type" SortExpression="SolType" />
<asp:BoundField DataField="Version" HeaderText="Version" SortExpression="Version" />
<asp:BoundField DataField="Lic_Type" HeaderText="License Type" SortExpression="Lic_Type" />
<asp:BoundField DataField="Meap_Supp" HeaderText="Meap Support" SortExpression="Meap_Supp" />
<asp:BoundField DataField="Lic_From" HeaderText="License From" SortExpression="Lic_From" />
<asp:BoundField DataField="Lic_To" HeaderText="License To" SortExpression="Lic_To" />
<asp:BoundField DataField="Supp_From" HeaderText="Support From" SortExpression="Supp_From" />
<asp:BoundField DataField="Supp_To" HeaderText="Support To" SortExpression="Supp_To" />
<asp:BoundField DataField="Max_User" HeaderText="Max Users" SortExpression="Max_User" />
<asp:BoundField DataField="Max_Mach" HeaderText="Max Machines" SortExpression="Max_Mach" />
<asp:BoundField DataField="Mach_IP" HeaderText="Machine IP" SortExpression="Mach_IP" />
<asp:BoundField DataField="Mach_MAC" HeaderText="Machine MAC" SortExpression="Mach_MAC" />
</Columns>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#999999" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>

【问题讨论】:

    标签: c# gridview data-binding datasource page-index-changed


    【解决方案1】:

    调用Gen_Lic_Grid.DataBind();之前需要设置数据源。

    protected void gridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        Gen_Lic_Grid.PageIndex = e.NewPageIndex;
        Gen_Lic_Grid.DataSource = MyVariable;
        Gen_Lic_Grid.DataBind();
    }
    

    【讨论】:

    • 补充:当不使用像SqlDataSource这样的声明性数据源控件时。但是 OP 没有使用它,所以你的答案似乎是解决方案。
    • @TimSchmelter:我认为他们的意思是放在一条线上
    • 你如何定义datasource,因为老实说,我不明白。
    • @Syrion 只需在您的代码中包含 NeedDataSource 事件并在那里绑定数据源。下次使用 databind() 时,它会自动调用该事件,您无需在此处定义 ds(数据源)。
    • 好吧,我真的很抱歉提出愚蠢的问题,但 myvariable 到底是什么?
    【解决方案2】:

    我认为你应该使用PageIndexChanged 事件而不是PageIndexChanging。我想你还没有使用过NeedDataSource 事件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-11
      • 2014-06-15
      • 1970-01-01
      • 2011-06-07
      • 1970-01-01
      相关资源
      最近更新 更多