dpc:Creating a DataBound List of Radio Buttons--预览

来源:互联网 发布:sjf调度算法 编辑:程序博客网 时间:2024/05/16 12:45
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<% @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 Radiobuttonof.com" target=_blank>List,
    '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 of.com" target=_blank>List Demo</h1>
  This demo illustrates how to use data-binding to dynamically
  create a Radio button of.com" target=_blank>List based on database information.
  The data below is from the
  <a href="http://www.4guysfromrolla.com/webtech/chapters/">Sample Chapters Database</a>.
  First, the Radio button of.com" target=_blank>List is bound to the <code>tblPublishers</code> table.  Then,
  when you select a publisher, a DataGrid Web control is populated with
  the books provided by the selected publisher.  (Adding paging to the DataGrid would be
  a snap.  Just read: <a href="http://www.4guysfromrolla.com/webtech/072101-1.shtml">Paing
  Database Results in ASP.NET</a>!)
  <p><hr><p>

  <form runat="server">
    
    <b>Choose a Publisher's Books to View</b><br>
    <asp:Radiobuttonof.com" target=_blank>List 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" OnClick="btnViewBooks_Click" />
    
    <p align="center">
    <asp:label id="lblTitle" runat="server" Font-Name="Verdana"
          Font-Size="Large" Font-Bold="True" />
    <asp:datagrid id="dgBooks" runat="server"
      Font-Name="Verdana" Font-Size="Smaller"
      HeaderStyle-BackColor="Purple" HeaderStyle-ForeColor="White"
      HeaderStyle-Font-Size="Small" HeaderStyle-Font-Bold="True"
      AutoGenerateColumns="False">
    
      <Columns>
      
        <asp:BoundColumn HeaderText="Book Title" HeaderStyle-HorizontalAlign="Center"
                DataField="Title" />
        <asp:BoundColumn HeaderText="Synopsis" HeaderStyle-HorizontalAlign="Center"
                DataField="Description" />
      </Columns>
    </asp:datagrid>
    </p>
  </form> <

of.com" target=_blank>dpc:of.com" target=_blank>Creating a of.com" target=_blank>DataBound of.com" target=_blank>List of Radio Buttons--预览页面source code[等级:中]';return true">
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
原创粉丝点击