本来是研究模版接口的,但是后来发现用用户控件也能实现类似datalist的控件,自己感觉还算方便,不过不知道有没有实际作用。
更新按钮没有添加事件,但是如果要添加的话也是很简单地~
查看: http://my.ht91.com/aaronlly/test/test.aspx
test.aspx
Public
Sub page_load()
Sub page_load()
Dim strConn, strSQL As String
Dim myConn As OleDbConnection
Dim myCommand As OleDbCommand
Dim dr As OleDbDataReader
strSQL = "select * from member order by id"
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(".") & "/db1.mdb"
myConn = New OleDbConnection(strConn)
myCommand = New OleDbCommand(strSQL, myConn)
myConn.Open()
dr = myCommand.ExecuteReader()
While dr.Read
Dim tt As New testuc_ascx
PlaceHolder1.Controls.Add(tt)
tt.idnum = dr("id")
tt.username = dr("user")
End While
myConn.Close()
End Sub
testuc.ascx
Public
Property idnum()
Property idnum() As String
Get
Return idnumtext.Text
End Get
Set(ByVal value As String)
idnumtext.Text = value
End Set
End Property

Public
Property username()
Property username() As String
Get
Return usernametext.Text
End Get
Set(ByVal value As String)
usernametext.Text = value
End Set
End Property

Sub edit_click()
Sub edit_click(ByVal sender As Object, ByVal e As EventArgs)
panel1.Visible = True
usernametext.Visible = False
edit.Visible = False
End Sub

Sub cancel_click()
Sub cancel_click(ByVal sender As Object, ByVal e As EventArgs)
panel1.Visible = False
usernametext.Visible = True
edit.Visible = True
nametext.Text = ""
End Sub
id:
<
asp:Label
runat
="server"
ID
="idnumtext"
></
asp:Label
><
br
/>
name:
<
asp:Label
runat
="server"
ID
="usernametext"
></
asp:Label
>
<
asp:Panel
runat
="server"
ID
="panel1"
Visible
=false
>
<
asp:TextBox
runat
="server"
ID
="nametext"
></
asp:TextBox
>
<
asp:Button
runat
="server"
ID
="save"
Text
="save"
></
asp:Button
>
<
asp:Button
runat
="server"
ID
="cancel"
Text
="cancel"
OnClick
=cancel_click
></
asp:Button
>
</
asp:Panel
>
<
br
/>
<
asp:LinkButton
runat
="server"
ID
="edit"
OnClick
="edit_click"
>
Edit
</
asp:LinkButton
>
<
hr
size
="1"
color
="silver"
width
="100%"
align
="left"
/>
本文介绍了一种使用用户控件(testuc.ascx)来显示数据库中成员信息的方法,通过在Page_Load事件中动态创建控件并设置属性,实现了类似DataList的功能。文章详细展示了从数据库读取数据到用户控件的绑定过程。
442

被折叠的 条评论
为什么被折叠?



