分享
 
 
 

datagrid分页《非控件版》

王朝c#·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

首先对我之前的发表的那篇补充一下:当你在你的建立的工程中要用到我做的那个用户控件的话:声明 Protected DataGridPage1 As DataGridPage,前是你拖进来的控件名,后是你定义用户控件。然后在你代码中要用你的控件就写上:

DataGridPage1.SetTarget(MyDataGrid, New BindDataDelegate(AddressOf binddata))

DataGridPage1.SetStyle(10, False)

下划线部分是你自己写的一个绑定之类的涵数。SUB,FUNCTION 等。

以下是我不做成控件时的代码:

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">第一頁</asp:LinkButton>

<asp:LinkButton id="LinkButton2" style="Z-INDEX: 103; LEFT: 64px; POSITION: absolute; TOP: 96px"

runat="server" Width="56px">前一頁</asp:LinkButton>

<asp:LinkButton id="LinkButton3" style="Z-INDEX: 104; LEFT: 120px; POSITION: absolute; TOP: 96px"

runat="server" Width="48px">後一頁</asp:LinkButton>

<asp:LinkButton id="LinkButton4" style="Z-INDEX: 105; LEFT: 176px; POSITION: absolute; TOP: 96px"

runat="server" Width="80px">最後一頁</asp:LinkButton>

<asp:Label id="Label1" style="Z-INDEX: 106; LEFT: 552px; POSITION: absolute; TOP: 80px" runat="server"

Width="56px">跳轉到:</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代码:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

' ページを初期化するユーザー コードをここに挿入します。

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

'???接

CN.Close()

End Try

'排序

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

'得到排序的列

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'>當前頁為:" & (MyDataGrid.CurrentPageIndex + 1) & "頁</font>]"

lblPageCount.Text = "[<font color='blue'>共:" & MyDataGrid.PageCount & "頁</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

完成;

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有