Add some functions to the last DataGrid page!

Source: Internet
Author: User

<% @ Import Namespace = "System. Data" %>

<Html>
<Script language = "C #" runat = "server">

ICollection CreateDataSource (){
DataTable dt = new DataTable ();
DataRow dr;

Dt. Columns. Add (new DataColumn ("IntegerValue", typeof (Int32 )));
Dt. Columns. Add (new DataColumn ("StringValue", typeof (string )));
Dt. Columns. Add (new DataColumn ("DateTimeValue", typeof (string )));
Dt. Columns. Add (new DataColumn ("BoolValue", typeof (bool )));

For (int I = 0; I <200; I ++ ){
Dr = dt. NewRow ();

Dr [0] = I;
Dr [1] = "Item" + Int32.ToString (I );
Dr [2] = DateTime. Now. tow.datestring ();
Dr [3] = (I % 2! = 0 )? True: false;

Dt. Rows. Add (dr );
}

DataView dv = new DataView (dt );
Return dv;
}

Void Page_Load (Object sender, EventArgs e ){
If (chk1.Checked ){
MyDataGrid. PagerStyle. Visible = true;
}
Else {
MyDataGrid. PagerStyle. Visible = false;
}

BindGrid ();
}

Void PagerButtonClick (Object sender, EventArgs e ){
// Used by external paging UI
String arg = (LinkButton) sender). CommandArgument;

Switch (arg)
{
Case ("next "):
If (MyDataGrid. CurrentPageIndex <(MyDataGrid. PageCount-1 ))
MyDataGrid. CurrentPageIndex ++;
Break;
Case ("prev "):
If (MyDataGrid. CurrentPageIndex> 0)
MyDataGrid. CurrentPageIndex --;
Break;
Case ("last "):
MyDataGrid. CurrentPageIndex = (MyDataGrid. PageCount-1 );
Break;
Default:
// Page number
MyDataGrid. CurrentPageIndex = arg. ToInt32 ();
Break;
}
BindGrid ();
}

Void MyDataGrid_Page (Object sender, DataGridPageChangedEventArgs e ){
// Used by built-in pager. CurrentPageIndex already set
BindGrid ();
}

Void BindGrid (){
MyDataGrid. DataSource = CreateDataSource ();
MyDataGrid. DataBind ();
ShowStats ();
}

Void ShowStats (){
LblCurrentIndex. Text = "CurrentPageIndex is" + MyDataGrid. CurrentPageIndex;
LblPageCount. Text = "PageCount is" + MyDataGrid. PageCount;
}


</Script>

<Body>

<H3> <font face = "Verdana"> Providing Alternate Paging UI </font>

<Form runat = server>

<ASP: DataGrid id = "MyDataGrid" runat = "server"
AllowPaging = "True"
PageSize = "10"
PagerStyle-Mode = "NumericPages"
PagerStyle-HorizontalAlign = "Right"
OnPageIndexChanged = "MyDataGrid_Page"
BorderColor = "black"
BorderWidth = "1"
GridLines = "Both"
CellPadding = "3"
CellSpacing = "0"
Font-Name = "Verdana"
Font-Size = "8pt"
HeaderStyle-BackColor = "# aaaadd"
AlternatingItemStyle-BackColor = "# eeeeee"
/>

<P>
<Asp: LinkButton id = "btnPrev" runat = "server"
Text = "Previous page"
CommandArgument = "prev"
ForeColor = "navy"
Font-Name = "verdana" Font-size = "8pt"
OnClick = "PagerButtonClick"
/>

<Asp: LinkButton id = "btnNext" runat = "server"
Text = "Next page"
CommandArgument = "next"
ForeColor = "navy"
Font-Name = "verdana" Font-size = "8pt"
OnClick = "PagerButtonClick"
/>

<Asp: LinkButton id = "btnPage8" runat = "server"
Text = "Go to Page 8"
CommandArgument = "7"
ForeColor = "navy"
Font-Name = "verdana" Font-size = "8pt"
OnClick = "PagerButtonClick"
/>

<Asp: LinkButton id = "btnFirst" runat = "server"
Text = "Go to the first page"
CommandArgument = "0"
ForeColor = "navy"
Font-Name = "verdana" Font-size = "8pt"
OnClick = "PagerButtonClick"
/>

<Asp: LinkButton id = "btnLast" runat = "server"
Text = "Go to the last page"
CommandArgument = "last"
ForeColor = "navy"
Font-Name = "verdana" Font-size = "8pt"
OnClick = "PagerButtonClick"
/>


<P>
<Asp: Checkbox id = "chk1" runat = "server"
Text = "Show built-in pager"
Font-Name = "Verdana"
Font-Size = "8pt"
AutoPostBack = "true"
/>

<P>
<Table bgcolor = "# eeeeee" cellpadding = "6"> <tr> <td nowrap> <font face = "Verdana" size = "-2">

<Asp: Label id = "lblCurrentIndex" runat = "server"/> <br>
<Asp: Label id = "lblPageCount" runat = "server"/> <br>

</Font> </td> </tr> </table>
</Form>

</Body>
</Html>

Author: jspfuns


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.