实现GridView寻呼功能的四个重要步骤
1、设置AllowPaging='True '
2、PageSize=设定每页的记录数。
3、寻呼事件OnPageIndexChanging=设置寻呼事件;此示例中的分页事件被命名为:Page_Change
前三个步骤具体为以下示例中的蓝色部分。
ASP : GridView id=' GridView1' runat=' server ' autogenerate columns=' false '
onrowcommand=' grid _ row _ com ' allowpaging=' true '
pagesize='5' onpageindexchanging=' page _ change '
4、编辑分页活动。
(1)、设置GridView.pageIndex属性;
) 2、重新绑定GridView数据源。
protectedvoidpage _ change (对象发送器,GridViewPageEventArgs e ) )。
{
GridView1. page index=e.new page index;
My_DataBind (;
}
其中:My_DataBind ()是此页的数据绑定函数。 具体如下。
protectedvoidpage _ load (对象发送器,事件发生器) ) ) ) ) ) ) ) )。
{
if (! IsPostBack )
{
My_DataBind (;
}
}
保护性void my _ databind (
{
string my _ constring=configuration manager.appsettings [ ' db _ tome1connectionstring ' ];
sqlconnection my _ con=new sqlconnection (my _ constring;
string my _ sel=' select * fromtb _ goods info ';
sqldataadaptermy _ ada=newsqldataadapter (my _ sel,My_Con );
DataSet My_Set=new DataSet (;
my_ada.fill(my_set,' Mytable ';
GridView1. data source=my _ set.tables [ ' my table ' ];
GridView1. datakeynames=new string [ ] { ' goods id ' };
GridView1.DataBind (;
My_Con.Close (;
}