欢迎进入.NET社区论坛,与200万技术人员互动交流 >>进入 ////////////////分页处理程序;
void Page_Load(Object sender, EventArgs e)
{
if (CheckBox1.Checked)
ItemsGrid.PagerStyle.Mode=PagerMode.NumericPages;
else
ItemsGrid.PagerStyle.Mode=PagerMode.NextPrev;
if (!IsPostBack)
{
start_index = 0;
ItemsGrid.VirtualItemCount=100;
}
BindGrid();
}
/////////////邦定公用函数;
void BindGrid()
{
ItemsGrid.DataSource=CreateDataSource();
ItemsGrid.DataBind();
}
///////////////////////// 数据库的链 接在前面已经发表过的,!
<asp:DataGrid id="ItemsGrid" runat="server"
BorderColor="black"
BorderWidth="1"
CellPadding="3" //行间隔;
AllowPaging="true" //换页开关;
AllowCustomPaging="true" //
BackImageUrl="Images\image1.jpg?http://www.xvna.com" //背景图象;
AutoGenerateColumns="false" //改变属性数据格会不一样有:true & false;
OnPageIndexChanged="Grid_Change"> //分页驱动程序ID
//分页默认样式;
<PagerStyle NextPageText="Forward"
PrevPageText="Back"
Position="Bottom"
PageButtonCount="5"
BackColor="#00aaaa">
</PagerStyle>
<AlternatingItemStyle BackColor="yellow">
</AlternatingItemStyle>
<HeaderStyle BackColor="#00aaaa">
</HeaderStyle>
<Columns>
<asp:BoundColumn HeaderText="Number"
DataField="IntegerValue"/>
<asp:BoundColumn
HeaderText="Item"
DataField="StringValue"/>
<asp:BoundColumn
HeaderText="Price"
DataField="CurrencyValue"
DataFormatString="{0:c}">
<ItemStyle HorizontalAlign="right">
</ItemStyle>
</asp:BoundColumn>
</Columns>
</asp:DataGrid>
<br>
//选择数字显示分页
<asp:CheckBox id="CheckBox1"
Text = "Show page navigation"
AutoPostBack="true"
runat="server"/>