[原创]将数据绑定至页面的两个Textbox控件上,并且可以通过按钮实现分页

数据绑定至Textbox控件并实现分页
None.gif    Dim conn As New SqlConnection("data source=localhost;initial catalog=pubs;user id=sa;pwd=SC")
None.gif    
Dim com As New SqlDataAdapter("select au_lname,zip from authors", conn)
None.gif    
Dim ds As New DataSet
None.gif    
Dim dv As DataView
None.gif
ExpandedBlockStart.gifContractedBlock.gif    
Private Sub Page_Load()Sub Page_Load(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles MyBase.Load
InBlock.gif        com.Fill(ds, 
"table")
InBlock.gif        dv 
= ds.Tables("table").DefaultView 'dv为dataview 设置为默认视图
InBlock.gif
        If Not Page.IsPostBack Then
InBlock.gif            Session(
"page"= 1
InBlock.gif        
End If
InBlock.gif        Page.DataBind()
ExpandedBlockEnd.gif    
End Sub

None.gif
ExpandedBlockStart.gifContractedBlock.gif    
Private Sub TextBox1_DataBinding()Sub TextBox1_DataBinding(ByVal sender As ObjectByVal e As System.EventArgs) Handles TextBox1.DataBinding
InBlock.gif        
Dim page As Integer = CType(Session("page"), Integer)
InBlock.gif        TextBox1.Text 
= dv(page)("au_lname"'dv(0)("au_lanem") 代表视图中第1条记录的au_laname字段
InBlock.gif
        TextBox2.Text = dv(page)("zip")
ExpandedBlockEnd.gif    
End Sub

None.gif
ExpandedBlockStart.gifContractedBlock.gif    
Private Sub Button2_Click()Sub Button2_Click(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles Button2.Click
InBlock.gif
ExpandedBlockEnd.gif    
End Sub

None.gif
ExpandedBlockStart.gifContractedBlock.gif    
Private Sub Button3_Click()Sub Button3_Click(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles Button3.Click
InBlock.gif        
Dim page As Integer = CType(Session("page"), Integer)
InBlock.gif        page 
+= 1
InBlock.gif        
If page > dv.Count - 1 Then
InBlock.gif            page 
-= 1
InBlock.gif        
End If
InBlock.gif        Session(
"page"= page
ExpandedBlockEnd.gif    
End Sub

转载于:https://www.cnblogs.com/xzlang/archive/2005/02/02/100964.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值