Dpc:creating a databound List of Radio buttons--preview
Source: Internet
Author: User
<% @Import namespace= "System.Data"%>
<% @Import namespace= "System.Data.SqlClient"%>
<script language= "VB" runat= "Server" >
Sub Page_Load (sender as Object, E as EventArgs)
If not Page.IsPostBack Then
Binddata ()
End If
End Sub
Sub Binddata ()
' 1. Create a connection
Dim MyConnection as New SqlConnection (ConfigurationSettings.AppSettings ("connectionString"))
' 2. Create the Command object, passing in the SQL string
Const strSQL as String = "Select PublisherID, Name from Tblpublishers order by name"
Dim mycommand as New SqlCommand (strSQL, MyConnection)
Sub Btnviewbooks_click (sender as Object, E as EventArgs)
' If the user has not selected a item from the RadioButtonList,
' Do nothing
If Radlstpubs.selecteditem is Nothing Then Exit Sub
' 1. Create a connection
Dim MyConnection as New SqlConnection (ConfigurationSettings.AppSettings ("connectionString"))
' 2. Create the Command object, passing in the SQL string
Dim strSQL as String = "SELECT Title, Description from Tblbooks" & _
"WHERE PublisherID =" & RadlstPubs.SelectedItem.Value & _
"ORDER by Title"
Dim mycommand as New SqlCommand (strSQL, MyConnection)
Lbltitle.text = "books published by" & RadlstPubs.SelectedItem.Text
End Sub
</script>
<body>
This demo illustrates you to use data-binding to dynamically
Create a radio button list based on database information.
The data below is from the
<a href= "http://www.4guysfromrolla.com/webtech/chapters/" >sample chapters Database</a>.
The radio button list is bound to the <code>tblPublishers</code> table. Then,
When you are select a Publisher, a DataGrid Web control are populated with
The books provided by the selected publisher. (Adding paging to the DataGrid would is
A snap. Just read: <a href= "http://www.4guysfromrolla.com/webtech/072101-1.shtml" >paing
Database Results in asp.net</a>!)
<p>
<form runat= "Server" >
<b>choose a Publisher ' s books to view</b><br>
<asp:radiobuttonlist id= "radlstpubs" runat= "Server" Font-name= "Verdana"
Datavaluefield= "PublisherID" datatextfield= "Name"/>
<br>
<asp:button id= "Btnviewbooks" runat= "Server" Font-name= "Verdana"
Text= "View published books"/>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.