<% 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)
    myConnection.Open()
    radlstPubs.DataSource = myCommand.ExecuteReader(CommandBehavior.CloseConnection)
    radlstPubs.DataBind()  
  End Sub
  Sub btnViewBooks_Click(sender as Object, e as EventArgs)
    'If the user has not selected an 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)
    myConnection.Open()
    dgBooks.DataSource = myCommand.ExecuteReader(CommandBehavior.CloseConnection)
    dgBooks.DataBind()  
    
    lblTitle.Text = "Books Published by " & radlstPubs.SelectedItem.Text
  End Sub
</script>
<html>
<body>
  <h1>Radio Button List Demo</h1>
  This demo illustrates how to use data-binding to dynamically
  create a radio button list based on database information.
  The data below is from the
  <a />
      </Columns>
    </asp:datagrid>
    </p>
  </form> <
			
dpc:Creating a DataBound List of Radio Buttons--预览
                    80酷酷网    80kuku.com 
       
  
 
 
  
