1


<%

@ Control Language="vb" AutoEventWireup="false" Codebehind="BestList.ascx.vb" Inherits="MoaWap.BestList" TargetSchema="http://schemas.microsoft.com/Mobile/WebUserControl" %>
2


<%

@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %>
3

<mobile:list id="list" Decoration="Bulleted" runat="server"></mobile:list>
4

<mobile:Panel id="Panel1" runat="server" BreakAfter="True">
5

<mobile:Label id="Label1" runat="server" BreakAfter="False">[</mobile:Label>
6

<mobile:Label id="lbl_currpage" runat="server" BreakAfter="False">1</mobile:Label>
7

<mobile:Label id="Label2" runat="server" BreakAfter="False">/</mobile:Label>
8

<mobile:Label id="lbl_count" runat="server" BreakAfter="False">0</mobile:Label>
9

<mobile:Label id="Label3" runat="server" BreakAfter="False">] </mobile:Label>
10

<mobile:Label id="lbl_RoteCount" runat="server" BreakAfter="False">0</mobile:Label>
11

<mobile:Label id="Label5" runat="server" BreakAfter="False">条记录</mobile:Label>
12

</mobile:Panel>
13

<mobile:Panel id="Panel2" runat="server" BreakAfter="True">
14

<mobile:Command id="btn_first" runat="server" BreakAfter="False" Visible="False">[首页]</mobile:Command>
15

<mobile:command id="btn_syy" runat="server" BreakAfter="False" Visible="False">[上页]</mobile:command>
16

<mobile:command id="btn_xyy" runat="server" BreakAfter="False" Visible="False">[下页]</mobile:command>
17

<mobile:Command id="btn_end" runat="server" BreakAfter="False" Visible="False">[末页]</mobile:Command>
18

</mobile:Panel>
19

<mobile:Panel id="Panel3" runat="server">
20

<mobile:Label id="Label4" runat="server" BreakAfter="False">转向</mobile:Label>
21

<mobile:TextBox id="txt_go" runat="server" BreakAfter="False" Numeric="True" Size="2">1</mobile:TextBox>
22

<mobile:Command id="btn_go" runat="server" BreakAfter="False">GO</mobile:Command>
23

</mobile:Panel>
24

<mobile:Label id="lbl_index" runat="server" Visible="False">0</mobile:Label>
vb代码 1

Imports System.Web.UI.MobileControls
2

3


委托定义#Region "委托定义"
4


Public Delegate Sub BestList_ItemCommand()Sub BestList_ItemCommand(ByVal sender As Object, ByVal e As System.Web.UI.MobileControls.ListCommandEventArgs)
5


Public Delegate Sub BestList_PageIndexChange()Sub BestList_PageIndexChange(ByVal sender As Object)
6

#End Region
7

8


Public MustInherit Class BestListClass BestList
9

Inherits System.Web.UI.MobileControls.MobileUserControl
10

11


Web 窗体设计器生成的代码#Region " Web 窗体设计器生成的代码 "
12

13

'该调用是 Web 窗体设计器所必需的。
14


<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()Sub InitializeComponent()
15

16

End Sub
17

Protected WithEvents list As System.Web.UI.MobileControls.List
18

Protected WithEvents Label1 As System.Web.UI.MobileControls.Label
19

Protected WithEvents lbl_currpage As System.Web.UI.MobileControls.Label
20

Protected WithEvents Label2 As System.Web.UI.MobileControls.Label
21

Protected WithEvents lbl_count As System.Web.UI.MobileControls.Label
22

Protected WithEvents Label3 As System.Web.UI.MobileControls.Label
23

Protected WithEvents lbl_RoteCount As System.Web.UI.MobileControls.Label
24

Protected WithEvents Label5 As System.Web.UI.MobileControls.Label
25

Protected WithEvents Panel1 As System.Web.UI.MobileControls.Panel
26

Protected WithEvents btn_first As System.Web.UI.MobileControls.Command
27

Protected WithEvents btn_syy As System.Web.UI.MobileControls.Command
28

Protected WithEvents btn_xyy As System.Web.UI.MobileControls.Command
29

Protected WithEvents btn_end As System.Web.UI.MobileControls.Command
30

Protected WithEvents Panel2 As System.Web.UI.MobileControls.Panel
31

Protected WithEvents lbl_index As System.Web.UI.MobileControls.Label
32

Protected WithEvents Panel3 As System.Web.UI.MobileControls.Panel
33

Protected WithEvents Label4 As System.Web.UI.MobileControls.Label
34

Protected WithEvents txt_go As System.Web.UI.MobileControls.TextBox
35

Protected WithEvents btn_go As System.Web.UI.MobileControls.Command
36

37

'注意: 以下占位符声明是 Web 窗体设计器所必需的。
38

'不要删除或移动它。
39

Private designerPlaceholderDeclaration As System.Object
40

41


Private Sub Page_Init()Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
42

'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
43

'不要使用代码编辑器修改它。
44

InitializeComponent()
45

End Sub
46

47

#End Region
48

49


变量及事件声明#Region "变量及事件声明"
50

Private MyPageSize As Integer = 10
51

Private MyDataSoune As DataTable
52

Public Event BestListItemCommand As BestList_ItemCommand
53

Public Event BestListPageIndexChange As BestList_PageIndexChange
54

#End Region
55

56


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

'在此处放置初始化页的用户代码
58

End Sub
59

60


属性定义#Region "属性定义"
61

62

'''<summary>
63

''' 列表集合
64

''' </summary>
65


Public ReadOnly Property Items()Property Items() As System.Web.UI.MobileControls.MobileListItemCollection
66

Get
67

Return list.Items
68

End Get
69

End Property
70

''' <summary>
71

''' 每页的记录数
72

''' </summary>
73


Public Property PageSize()Property PageSize() As Integer
74

Get
75

Return MyPageSize
76

End Get
77

Set(ByVal Value As Integer)
78

MyPageSize = Value
79

End Set
80

End Property
81

'''<summary>
82

''' 当前索引号
83

'''</summary>
84


Public Property SelectIndex()Property SelectIndex() As Integer
85

Get
86

If lbl_index.Text <> "" Then
87

Return Convert.ToInt32(lbl_index.Text)
88

Else
89

Return -1
90

End If
91

End Get
92

Set(ByVal Value As Integer)
93

lbl_index.Text = Convert.ToString(Value)
94

End Set
95

End Property
96

'''<summary>
97

''' 数据源表
98

'''</summary>
99


Public Property DataSoune()Property DataSoune() As DataTable
100

Get
101

Return MyDataSoune
102

End Get
103

Set(ByVal Value As DataTable)
104

MyDataSoune = Value
105

End Set
106

End Property
107

'''<summary>
108

''' 列表文本数据字段
109

'''</summary>
110


Public Property DataTextField()Property DataTextField() As String
111

Get
112

Return list.DataTextField
113

End Get
114

Set(ByVal Value As String)
115

list.DataTextField = Value
116

End Set
117

End Property
118

''' <summary>
119

''' 列表值数据字段
120

''' </summary>
121


Public Property DataValueField()Property DataValueField() As String
122

Get
123

Return list.DataValueField
124

End Get
125

Set(ByVal Value As String)
126

list.DataValueField = Value
127

End Set
128

End Property
129

'''<summary>
130

''' 页数
131

''' </summary>
132


Public ReadOnly Property PageCount()Property PageCount() As Integer
133

Get
134

Return Convert.ToInt32(lbl_count.Text.Trim())
135

End Get
136

End Property
137

138

#End Region
139

140

'''<summary>
141

'''列表框复位
142

'''</summary>
143


Public Sub ItemClear()Sub ItemClear()
144

list.Items.Clear()
145

list.DataSource = Nothing
146

list.DataTextField = ""
147

list.DataValueField = ""
148

lbl_index.Text = "0"
149

lbl_currpage.Text = "1"
150

End Sub
151

152

'''ItemCommand事件激活
153


Private Sub list_ItemCommand()Sub list_ItemCommand(ByVal sender As Object, ByVal e As System.Web.UI.MobileControls.ListCommandEventArgs) Handles list.ItemCommand
154

lbl_index.Text = e.ListItem.Index.ToString()
155

'If Not (BestListItemCommand Is Nothing) Then
156

RaiseEvent BestListItemCommand(sender, e)
157

'End If
158

End Sub
159

160

'''<summary>
161

''' 数据绑定
162

''' </summary>
163


Public Sub DataBindList()Sub DataBindList()
164

If Not (MyDataSoune Is Nothing) Then
165

'得出当前记录总数
166

Dim RoteCount As Integer = MyDataSoune.Rows.Count
167

'当不同数据源绑定时恢复当前页为1(根据记录数判断是否是同一个数据源)
168

Dim OldRoteCount As Integer = Convert.ToInt32(lbl_RoteCount.Text.Trim())
169

If OldRoteCount <> 0 And OldRoteCount <> RoteCount Then
170

lbl_currpage.Text = "1"
171

End If
172

lbl_RoteCount.Text = RoteCount.ToString()
173
'得出页总数
Dim tespint As Integer = RoteCount Mod PageSize
If tespint > 0 Then
'lbl_count.Text = Convert.ToString(CInt(RoteCount / PageSize) + 1)
lbl_count.Text = Convert.ToString(CInt((RoteCount - tespint) / PageSize) + 1)
176

Else
177

lbl_count.Text = Convert.ToString(RoteCount / PageSize)
178

End If
179

If Convert.ToInt32(lbl_currpage.Text.Trim()) > 0 And Convert.ToInt32(lbl_currpage.Text.Trim()) <= Convert.ToInt32(lbl_count.Text.Trim()) Then
180

'据当前页求出本页的开始记录和结束记录索引
181

Dim start As Integer, tempend As Integer
182

start = (Convert.ToInt32(lbl_currpage.Text.Trim()) - 1) * PageSize
183

If Convert.ToInt32(lbl_currpage.Text.Trim()) = Convert.ToInt32(lbl_count.Text.Trim()) Then
184

tempend = RoteCount - 1
185

Else
186

tempend = start + PageSize - 1
187

End If
188

list.Items.Clear()
189

For i As Integer = start To tempend
190

'初始化列表框
191

Dim MyList As New MobileListItem
192

MyList.Value = MyDataSoune.Rows(i)(list.DataValueField.Trim()).ToString()
193

MyList.Text = MyDataSoune.Rows(i)(list.DataTextField.Trim()).ToString()
194

list.Items.Add(MyList)
195

Next
196

197

End If
198

'---------导航按钮控制
199

If Convert.ToInt32(lbl_count.Text.Trim()) <= 1 Then
200

'当只有一页时或没有记录时
201

btn_first.Visible = False
202

btn_syy.Visible = False
203

btn_xyy.Visible = False
204

btn_end.Visible = False
205

Panel1.Visible = False
206

ElseIf Convert.ToInt32(lbl_currpage.Text.Trim()) = 1 Then
207

'当为第一页时
208

btn_first.Visible = False
209

btn_syy.Visible = False
210

btn_xyy.Visible = True
211

btn_end.Visible = True
212

Panel1.Visible = True
213

ElseIf Convert.ToInt32(lbl_currpage.Text.Trim()) = Convert.ToInt32(lbl_count.Text.Trim()) Then
214

'当为最后一页时
215

btn_first.Visible = True
216

btn_syy.Visible = True
217

btn_xyy.Visible = False
218

btn_end.Visible = False
219

Panel1.Visible = True
220

ElseIf Convert.ToInt32(lbl_currpage.Text.Trim()) = 2 Then
221

'当为第二页时
222

btn_first.Visible = True
223

btn_syy.Visible = False
224

btn_xyy.Visible = True
225

btn_end.Visible = True
226

Panel1.Visible = True
227

ElseIf Convert.ToInt32(lbl_currpage.Text.Trim()) = Convert.ToInt32(lbl_count.Text.Trim()) - 1 Then
228

'当为最后一页时
229

btn_first.Visible = True
230

btn_syy.Visible = True
231

btn_xyy.Visible = False
232

btn_end.Visible = True
233

Panel1.Visible = True
234

Else
235

btn_first.Visible = True
236

btn_syy.Visible = True
237

btn_xyy.Visible = True
238

btn_end.Visible = True
239

Panel1.Visible = True
240

End If
241

End If
242

End Sub
243

244

'''翻页处理
245


Private Sub MyPageIdexChange()Sub MyPageIdexChange(ByVal key As String)
246

Select Case key
247

Case "first"
248

If Convert.ToInt32(lbl_count.Text.Trim()) > 0 Then
249

lbl_currpage.Text = "1"
250

End If
251

Case "top"
252

If Convert.ToInt32(lbl_currpage.Text.Trim()) > 1 Then
253

lbl_currpage.Text = Convert.ToString(Convert.ToInt32(lbl_currpage.Text.Trim()) - 1)
254

End If
255

Case "next"
256

If Convert.ToInt32(lbl_currpage.Text.Trim()) < Convert.ToInt32(lbl_count.Text.Trim()) Then
257

lbl_currpage.Text = Convert.ToString(Convert.ToInt32(lbl_currpage.Text.Trim()) + 1)
258

End If
259

Case "last"
260

If Convert.ToInt32(lbl_count.Text.Trim()) > 0 Then
261

lbl_currpage.Text = lbl_count.Text.Trim()
262

End If
263

Case "go"
264

If txt_go.Text.Trim() <> "" Then
265

Dim igo As Integer = CInt(txt_go.Text.Trim())
266

If igo <= Convert.ToInt32(lbl_count.Text.Trim()) And igo >= 1 Then
267

lbl_currpage.Text = txt_go.Text.Trim()
268

End If
269

End If
270

End Select
271

'触发用户控件的PageIdexChange事件
272

'If Not (BestListPageIndexChange Is Nothing) Then
273

RaiseEvent BestListPageIndexChange(Me)
274

'End If
275

End Sub
276

277

278


Private Sub btn_first_Click()Sub btn_first_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_first.Click
279

MyPageIdexChange("first")
280

End Sub
281

282


Private Sub btn_syy_Click()Sub btn_syy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_syy.Click
283

MyPageIdexChange("top")
284

End Sub
285

286


Private Sub btn_xyy_Click()Sub btn_xyy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_xyy.Click
287

MyPageIdexChange("next")
288

End Sub
289

290


Private Sub btn_end_Click()Sub btn_end_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_end.Click
291

MyPageIdexChange("last")
292

End Sub
293

294


Private Sub btn_go_Click()Sub btn_go_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_go.Click
295

MyPageIdexChange("go")
296

End Sub
297

End Class
298

1


Public Class dzgw_dbgwClass dzgw_dbgw
2

Inherits System.Web.UI.MobileControls.MobilePage
3

Protected WithEvents Label1 As System.Web.UI.MobileControls.Label
4

Protected WithEvents Link1 As System.Web.UI.MobileControls.Link
5

Protected WithEvents Panel1 As System.Web.UI.MobileControls.Panel
6

Protected WithEvents Link2 As System.Web.UI.MobileControls.Link
7

Protected WithEvents Label2 As System.Web.UI.MobileControls.Label
8

Protected WithEvents FrmMain As System.Web.UI.MobileControls.Form
9

'声明自定义控件
10

Private WithEvents blist_dbgw As BestList
11

12


Web 窗体设计器生成的代码#Region " Web 窗体设计器生成的代码 "
13
14

'该调用是 Web 窗体设计器所必需的。
15


<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()Sub InitializeComponent()
16

17

End Sub
18

19


Private Sub Page_Init()Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
20

'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
21

'不要使用代码编辑器修改它。
22

InitializeComponent()
23

End Sub
24
25

#End Region
26

27

Private uid As String
28

''用于事件关联
29

'Private WithEvents blist As BestList
30


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

''-------页面访问权限控制--------
32

'If Not Config.ChkPage(Convert.ToString(Session("xtqx")), "0102000000") Then
33

' Me.RedirectToMobilePage("../index.aspx")
34

'End If
35

'获取用户控件
36

blist_dbgw = CType(Me.FindControl("blist_dzgw"), BestList)
37

38

End Sub
39

40


Private Sub blist_dbgw_ItemCommand()Sub blist_dbgw_ItemCommand(ByVal sender As Object, ByVal e As System.Web.UI.MobileControls.ListCommandEventArgs) Handles blist_dbgw.BestListItemCommand
41

If Not (e.ListItem Is Nothing) Then
42

'blist_dbgw.SelectIndex的使用
43

Response.Write(blist_dbgw.Items(blist_dbgw.SelectIndex).Text)
44

End If
45

End Sub
46

47


Private Sub blist_fgs_dbgweIndexChange()Sub blist_fgs_dbgweIndexChange(ByVal sender As Object) Handles blist_dbgw.BestListPageIndexChange
48

'重新绑定一下数据
49

filldata()
50

End Sub
51

52


Private Sub FrmMain_Activate()Sub FrmMain_Activate(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FrmMain.Activate
53

filldata()
54

End Sub
55

56


Private Sub filldata()Sub filldata()
57

Dim sqlstr As String = "select * from pt_login"
58

'初始化列表
59

blist_dbgw.DataTextField = "v_xm"
60

blist_dbgw.DataValueField = "v_dlid"
61

blist_dbgw.PageSize = 1
62

blist_dbgw.DataSoune = class_data.foundcnx(sqlstr, "t_dbsw").Tables(0)
63

blist_dbgw.DataBindList()
64

End Sub
65

End Class
66

效果