asp.net gridview

本文详细介绍了如何在GridView中实现分页与排序功能,包括使用ASP.NET的GridView控件进行基本配置,以及如何自定义分页显示和排序操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 利用GridView自带的分页

<table width="100%" cellpadding="0" cellspacing="0" style="border-collapse: collapse;border: 0px; table-layout: fixed">
            <tr>
                <td style="width:10px"></td>
                <td style="width: 100%; padding: 0px" valign="top" colspan="10">
                    <asp:GridView ID="GridView_SUB1" runat="server" Width="100%" AutoGenerateColumns="False"
                        BorderStyle="None" BorderWidth="1px" AllowPaging="True"
                        HorizontalAlign="Center" onrowdatabound="GridView_SUB1_RowDataBound"
                        onpageindexchanged="GridView_SUB1_PageIndexChanged"
                        onpageindexchanging="GridView_SUB1_PageIndexChanging" AllowSorting="True"
                        onsorting="GridView_SUB1_Sorting">
                        <PagerSettings FirstPageText="首页" LastPageText="末页" Mode="NextPreviousFirstLast" NextPageText="下一页" PreviousPageText="上一页" Visible="true" />
                        <PagerStyle HorizontalAlign="Right" />
                        <HeaderStyle BackColor="Silver" />
                        <Columns>
                            <asp:BoundField  HeaderText="序号"/>
                            <asp:BoundField HeaderText="表单号" DataField="form_no" SortExpression="form_no"/>
                            <asp:BoundField HeaderText="公司账簿" DataField="item_name" SortExpression="item_name"/>
                            <asp:BoundField HeaderText="行号" DataField="line_no" SortExpression="line_no"/>
                            <asp:BoundField HeaderText="单据来源" DataField="f17" SortExpression="f17"/>
                            <asp:BoundField HeaderText="变动类型" DataField="f15" SortExpression="f15"/>
                            <asp:BoundField HeaderText="备注" DataField="f14" SortExpression="f14"/>
                            <asp:BoundField HeaderText="资产编号" DataField="F21" SortExpression="F21"/>
                            <asp:BoundField HeaderText="序列号" DataField="f24" SortExpression="f24"/>
                            <asp:BoundField HeaderText="是否OA" DataField="f29" SortExpression="f29"/>
                            <asp:BoundField HeaderText="原保管部门" DataField="F04" SortExpression="F04"/>
                            <asp:BoundField HeaderText="原保管人" DataField="F05" SortExpression="F05"/>
                            <asp:BoundField HeaderText="转入部门" DataField="F07" SortExpression="F07"/>
                            <asp:BoundField HeaderText="转入保管人" DataField="F08" SortExpression="F08"/>
                            <asp:BoundField HeaderText="申请人" DataField="f01" SortExpression="f01"/>
                            <asp:BoundField HeaderText="表单状态" DataField="form_status" SortExpression="form_status"/>
                        </Columns>
                    </asp:GridView>
                </td>
                <td style="width:10px"></td>
            </tr>
         </table>

 

后台代码:

 protected void GridView_SUB1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                int id = GridView_SUB1.PageIndex * GridView_SUB1.PageSize + e.Row.RowIndex + 1;
                e.Row.Cells[0].Text = id.ToString();
            }
        }

 

protected void GridView_SUB1_PageIndexChanged(object sender, EventArgs e)
        {
            BindGridView_SUB1(true);
        }

        protected void GridView_SUB1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            this.GridView_SUB1.PageIndex = e.NewPageIndex;
        }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值