DataGrid pagination "non-control version"

Source: Internet
Author: User
Tags sort tostring visual studio
datagrid| Pagination | The control first adds to my previous post: When you use the user control I made in your project: Declare Protected DataGridPage1 as Datagridpage, which is the name of the control you dragged in before. After you define the user control. Then use your control in your code to write:

Datagridpage1.settarget (Mydatagrid, New binddatadelegate (AddressOf binddata))
Datagridpage1.setstyle (a False)

The underline part is the number of a binding you write yourself. Sub,function and so on.

Here's what I do when I don't make a control:

Html:

<%@ Page language= "vb" autoeventwireup= "false" codebehind= "Fenye.aspx.vb" inherits= "Datagridtitle.fenye"%>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" >
<HTML>
<HEAD>
<title>fenye</title>
<meta name= "generator" content= "Microsoft Visual Studio. NET 7.1" >
<meta name= "Code_language" content= "Visual Basic. NET 7.1" >
<meta name= "vs_defaultClientScript" content= "JavaScript" >
<meta name= "vs_targetschema" content= "http://schemas.microsoft.com/intellisense/ie5" >
</HEAD>
<body ms_positioning= "GridLayout" >
<form id= "Form1" method= "POST" runat= "Server" >
<font face= "MS UI Gothic" >
<asp:datagrid id= "Mydatagrid" style= "Z-INDEX:101; left:0px; Position:absolute; Top:112px "
runat= "Server" width= "744px" height= "224px" allowpaging= "True" >
<pagerstyle visible= "False" ></PagerStyle>
</asp:DataGrid>
<asp:linkbutton id= "LinkButton1" style= "z-index:102; left:8px; Position:absolute; Top:96px "
runat= "Server" width= "48px" height= "8px" > First homepage </asp:LinkButton>
<asp:linkbutton id= "LinkButton2" style= "z-index:103; left:64px; Position:absolute; Top:96px "
runat= "Server" width= "56px" > previous page </asp:LinkButton>
<asp:linkbutton id= "LinkButton3" style= "z-index:104; left:120px; Position:absolute; Top:96px "
runat= "Server" width= "48px" > Back </asp:LinkButton>
<asp:linkbutton id= "LinkButton4" style= "z-index:105; left:176px; Position:absolute; Top:96px "
runat= "Server" width= "80px" > last page </asp:LinkButton>
<asp:label id= "Label1" style= "z-index:106; left:552px; Position:absolute; top:80px "runat=" Server "
Width= "56px" > Jump to:</asp:label>
<asp:textbox id= "Txtgopage" style= "z-index:107; left:624px; Position:absolute; top:80px "
runat= "Server" width= "48px" height= "24px" ></asp:TextBox>
<asp:button id= "Btngo" style= "z-index:108; left:680px; Position:absolute; top:80px "runat=" Server "
height= "24px" width= "56px" text= "button" ></asp:Button>
<asp:label id= "Lblcurrentindex" style= "z-index:109; left:296px; Position:absolute; Top:88px "
runat= "Server" height= "24px" width= "120px" >Label</asp:Label>
<asp:label id= "Lblpagecount" style= "z-index:110; left:424px; Position:absolute; Top:88px "
runat= "Server" width= "112px" >Label</asp:Label></FONT>
</form>
</body>
</HTML>


Web code:

Private Sub Page_Load (ByVal sender as System.Object, ByVal e as System.EventArgs) Handles MyBase.Load
' ページを initial するユーザーコードをここに 挿 into します.
If not IsPostBack Then

ViewState ("strsort") = "OrderID"

Mydatagrid.datasource = GETDV (ViewState ("StrSort"). ToString ())

Mydatagrid.databind ()
Showstatspage ()
' Call Orderbind ()
End If
End Sub
Private Function GETDV (ByVal strsort as String) as DataView



Dim DV as DataView

Dim CN as New SqlConnection

Try



CN. ConnectionString = "Data source=yangchangquan;initial catalog=northwind;persist security Info=false;user Id=sa; Password=pass; "

CN. Open ()



Dim ADP as SqlDataAdapter = New SqlDataAdapter ("select * from Orders", CN)

Dim DS as New DataSet

Adp. Fill (DS)



DV = ds. Tables (0). DefaultView

Catch ex as Exception

#If DEBUG Then

Session ("Error") = ex. ToString ()

Response.Redirect (".. /error.aspx ")

#End If

Finally

'??? Pick up

CN. Close ()

End Try

' Sort

Dv. Sort = StrSort

Return DV

End Function




Private Sub Mydatagrid_sortcommand (ByVal source as System.Object, ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs)
Mydatagrid.currentpageindex = 0

' Get sorted columns

ViewState ("strsort") = E.sortexpression.tostring ()

Mydatagrid.datasource = GETDV (ViewState ("StrSort"). ToString ())

Mydatagrid.databind ()

Showstatspage ()
End Sub




Private Sub Btngo_click (ByVal sender as System.Object, ByVal e as System.EventArgs) Handles Btngo.click
Dim Pagei as Integer
If (Txtgopage.text <> "") Then
Pagei = CInt (Trim (Txtgopage.text))-1
If (pagei >= 0 and Pagei < (mydatagrid.pagecount)) Then
Mydatagrid.currentpageindex = Pagei
End If
End If
ViewState ("strsort") = "OrderID"

Mydatagrid.datasource = GETDV (ViewState ("StrSort"). ToString ())

Mydatagrid.databind ()
Showstatspage ()
End Sub

Private Sub Showstatspage ()
Lblcurrentindex.text = "[<font color= ' Blue ' > as Before:" & (Mydatagrid.currentpageindex + 1) & "page </font>] "
Lblpagecount.text = "[<font color= ' Blue ' > Total:" & mydatagrid.pagecount & "page </font>]"

End Sub

Private Sub LinkButton1_Click (ByVal sender as System.Object, ByVal e as System.EventArgs) Handles Linkbutton1.click
Mydatagrid.currentpageindex = 0
ViewState ("strsort") = "OrderID"

Mydatagrid.datasource = GETDV (ViewState ("StrSort"). ToString ())

Mydatagrid.databind ()
Showstatspage ()
End Sub

Private Sub Linkbutton4_click (ByVal sender as System.Object, ByVal e as System.EventArgs) Handles Linkbutton4.click
Mydatagrid.currentpageindex = (mydatagrid.pagecount-1)
ViewState ("strsort") = "OrderID"

Mydatagrid.datasource = GETDV (ViewState ("StrSort"). ToString ())

Mydatagrid.databind ()
Showstatspage ()
End Sub

Private Sub Linkbutton2_click (ByVal sender as System.Object, ByVal e as System.EventArgs) Handles Linkbutton2.click
If (Mydatagrid.currentpageindex > 0) Then
Mydatagrid.currentpageindex = mydatagrid.currentpageindex-1
ViewState ("strsort") = "OrderID"

Mydatagrid.datasource = GETDV (ViewState ("StrSort"). ToString ())

Mydatagrid.databind ()
Showstatspage ()
End If
End Sub

Private Sub Linkbutton3_click (ByVal sender as System.Object, ByVal e as System.EventArgs) Handles Linkbutton3.click
If (Mydatagrid.currentpageindex < (mydatagrid.pagecount-1)) Then
Mydatagrid.currentpageindex = Mydatagrid.currentpageindex + 1
ViewState ("strsort") = "OrderID"

Mydatagrid.datasource = GETDV (ViewState ("StrSort"). ToString ())

Mydatagrid.databind ()
Showstatspage ()
End If
End Sub

Complete



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.