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>
                " WHERE PublisherID = " & radlstPubs.SelectedItem.Value & _<br>
                " ORDER BY Title"<br>
        Dim myCommand as New SqlCommand(strSQL, myConnection)<br>
<br>
    myConnection.Open()<br>
<br>
    dgBooks.DataSource = myCommand.ExecuteReader(CommandBehavior.CloseConnection)<br>
    dgBooks.DataBind()  <br>
    <br>
    lblTitle.Text = "Books Published by " & radlstPubs.SelectedItem.Text<br>
  End Sub<br>
</script><br>
<br>
<html><br>
<body><br>
<br>
  <h1>Radio Button List Demo</h1><br>
  This demo illustrates how to use data-binding to dynamically<br>
  create a radio button list based on database information.<br>
  The data below is from the<br>
  <a href="http://www.4guysfromrolla.com/webtech/chapters/">Sample Chapters Database</a>.<br>
  First, the radio button list is bound to the <code>tblPublishers</code> table.  Then,<br>
  when you select a publisher, a DataGrid Web control is populated with<br>
  the books provided by the selected publisher.  (Adding paging to the DataGrid would be<br>
  a snap.  Just read: <a href="http://www.4guysfromrolla.com/webtech/072101-1.shtml">Paing<br>
  Database Results in ASP.NET</a>!)<br>
  <p><hr><p><br>
<br>
  <form runat="server"><br>
    <br>
    <b>Choose a Publisher's Books to View</b><br><br>
    <asp:radiobuttonlist id="radlstPubs" runat="server" Font-Name="Verdana"<br>
            DataValueField="PublisherID" DataTextField="Name" /><br>
    <br><br>
    <asp:button id="btnViewBooks" runat="server" Font-Name="Verdana"<br>
          Text="View Published Books" OnClick="btnViewBooks_Click" /><br>
    <br>
    <p align="center"><br>
    <asp:label id="lblTitle" runat="server" Font-Name="Verdana"<br>
          Font-Size="Large" Font-Bold="True" /><br>
    <asp:datagrid id="dgBooks" runat="server"<br>
      Font-Name="Verdana" Font-Size="Smaller"<br>
      HeaderStyle-BackColor="Purple" HeaderStyle-ForeColor="White"<br>
      HeaderStyle-Font-Size="Small" HeaderStyle-Font-Bold="True"<br>
      AutoGenerateColumns="False"><br>
    <br>
      <Columns><br>
      <br>
        <asp:BoundColumn HeaderText="Book Title" HeaderStyle-HorizontalAlign="Center"<br>
                DataField="Title" /><br>
        <asp:BoundColumn HeaderText="Synopsis" HeaderStyle-HorizontalAlign="Center"<br>
                DataField="Description" /><br>
      </Columns><br>
    </asp:datagrid><br>
    </p><br>
  </form> <br>
<br>

时间: 2024-10-03 10:19:23

DPC:Creating a DataBound List of Radio Buttons--预览页面source code[等级:中]的相关文章

DPC:Creating a DataBound List of Radio Buttons--PA

-------------------------------------------------------------------------------- For More Information on ASP.NET This article examines how to create a databound listbox using ASP.NET. For more information on ASP.NET be sure to check out the articles

DPC:Creating a DataBound List of Radio Buttons--PART1[等级:中]

Creating a DataBound List of Radio Buttons -------------------------------------------------------------------------------- For More Information on ASP.NET This article examines how to create a databound listbox using ASP.NET. For more information on

DPC:Creating a DataBound List of Radio Buttons--PART2[等级:中]

In Part 1 we looked at how to bind a DataReader to a radio button list, but how do we respond to the user's choice? In this part we'll look at how to display a list of books for the particular publisher the user selected from the databound radio butt

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

<% @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

ASP.NET 2.0数据教程之五十一:为GridView控件添加Radio Buttons列

返回"ASP.NET 2.0数据教程目录" 第51到53章为优化GridView系列 导言: GridView控件提供了大 量的内置功能.它包含了一系列的域(field)来显示诸如text.images. hyperlinks和buttons.另外它支持模板(template)用于用户自定义界面.我们 可以构建这样一个GridView控件,用户仅需要点击控件里的一个按钮,每一条记 录行都可以选择.编辑.删除.除了控件本身内置的功能外,在某些情况下,我 们添加一些额外的.控件没有内置的功

Handling Checkboxes, Radio Buttons and Select Options in jQuery [转]

I figured I'd share how I've dealt with some form elements in jQuery. Sometimes you have to look at the docs a few times before you get what you can do, so I think these examples might help someone out there. Here is how you can handle a change in a

android-在sdk中如何使用radio buttons解除AlertDialog?

问题描述 在sdk中如何使用radio buttons解除AlertDialog? 我创建了一个alertdialog,里面有俩个radio buttons,当用户选择一个选项时,我需要解除alertdialog,但是不知道怎么解除,请大家的帮忙. final CharSequence[] items = {""First Option""Second Option""}; AlertDialog.Builder builder = new Al

DPC: Creating a multicolumn Dropdownlist[等级:初 中]

Creating a multicolumn DropdownlistClick here to return to my article index One of the frequently asked questions over at Asplists.com is: "How do I create a multicolumn dropdownlist?". I have come up with two ways to accomplish this task. The f

Android开发指南(33) —— Multimedia and Camera - Camera

前言 本章内容为Android开发者指南的 Framework Topics/Multimedia and Camera/Camera章节,译为"摄像头",版本为Android 4.0 r1,翻译来自:"呆呆大虾",欢迎访问他的微博:"http://weibo.com/popapa",再次感谢"呆呆大虾" !期待你一起参与翻译Android的相关资料,联系我over140@gmail.com.   声明 欢迎转载,但请保留文章