asp.net กับ RadioButtonList อ่านข้อมูลจาก Database
Tag : - - - -
Date :
1 พ.ย. 2547 18:48:46
By :
bu
View :
2882
Reply :
1
No. 1
Guest
Code (VB.NET)
Function RadioButtonListDataTable()
Dim objConn As OleDbConnection
Dim dtAdapter As OleDbDataAdapter
Dim dt As New DataTable
Dim strConnString As String
strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="& _
Server.MapPath("database/mydatabase.mdb")&";"
objConn = New OleDbConnection(strConnString)
objConn.Open()
Dim strSQL As String
strSQL = "SELECT * FROM country"
dtAdapter = New OleDbDataAdapter(strSQL, objConn)
dtAdapter.Fill(dt)
dtAdapter = Nothing
objConn.Close()
objConn = Nothing
'*** RadioButtonList ***'
With Me.myRdoList1
.DataSource = dt
.DataTextField = "CountryName"
.DataValueField = "CountryCode"
.DataBind()
End With
'*** Default Value ***'
myRdoList1.SelectedIndex = myRdoList1.Items.IndexOf(myRdoList1.Items.FindByValue("TH")) '*** By DataValueField ***'
'myRdoList1.SelectedIndex = myRdoList1.Items.IndexOf(myRdoList1.Items.FindByText("Thailand")) '*** By DataTextField ***'
End Function