DPC:Creating a DataBound List of Radio Buttons--预览页面source code等级:中
<% @Import Namespace="System.Data" %><br>
<% @Import Namespace="System.Data.SqlClient" %><br>
<script language="vb" runat="server"><br>
Sub Page_Load(sender as Object, e as EventArgs)<br>
If Not Page.IsPostBack then<br>
BindData()<br>
End If <br>
End Sub<br>
<br>
<br>
Sub BindData()<br>
'1. Create a connection<br>
Dim myConnection as New SqlConnection(ConfigurationSettings.AppSettings("connectionString"))<br>
<br>
'2. Create the command object, passing in the SQL string<br>
Const strSQL as String = "SELECT PublisherID, Name FROM tblPublishers ORDER BY Name"<br>
Dim myCommand as New SqlCommand(strSQL, myConnection)<br>
<br>
myConnection.Open()<br>
<br>
radlstPubs.DataSource = myCommand.ExecuteReader(CommandBehavior.CloseConnection)<br>
radlstPubs.DataBind() <br>
<br>
End Sub<br>
<br>
<br>
<br>
Sub btnViewBooks_Click(sender as Object, e as EventArgs)<br>
'If the user has not selected an item from the radiobuttonlist,<br>
'do nothing<br>
If radlstPubs.SelectedItem Is Nothing then Exit Sub<br>
<br>
'1. Create a connection<br>
Dim myConnection as New SqlConnection(ConfigurationSettings.AppSettings("connectionString"))<br>
<br>
'2. Create the command object, passing in the SQL string<br>
Dim strSQL as String = "SELECT Title, Description FROM tblBooks " & _<br>
&
<% @Import Namespace="System.Data.SqlClient" %><br>
<script language="vb" runat="server"><br>
Sub Page_Load(sender as Object, e as EventArgs)<br>
If Not Page.IsPostBack then<br>
BindData()<br>
End If <br>
End Sub<br>
<br>
<br>
Sub BindData()<br>
'1. Create a connection<br>
Dim myConnection as New SqlConnection(ConfigurationSettings.AppSettings("connectionString"))<br>
<br>
'2. Create the command object, passing in the SQL string<br>
Const strSQL as String = "SELECT PublisherID, Name FROM tblPublishers ORDER BY Name"<br>
Dim myCommand as New SqlCommand(strSQL, myConnection)<br>
<br>
myConnection.Open()<br>
<br>
radlstPubs.DataSource = myCommand.ExecuteReader(CommandBehavior.CloseConnection)<br>
radlstPubs.DataBind() <br>
<br>
End Sub<br>
<br>
<br>
<br>
Sub btnViewBooks_Click(sender as Object, e as EventArgs)<br>
'If the user has not selected an item from the radiobuttonlist,<br>
'do nothing<br>
If radlstPubs.SelectedItem Is Nothing then Exit Sub<br>
<br>
'1. Create a connection<br>
Dim myConnection as New SqlConnection(ConfigurationSettings.AppSettings("connectionString"))<br>
<br>
'2. Create the command object, passing in the SQL string<br>
Dim strSQL as String = "SELECT Title, Description FROM tblBooks " & _<br>
&
| 对此文章发表了评论 |

