- 热门文章:
- · .NET几大热点问题(转)
- · DataList控件也玩分页 (转自aspcn.com)
- · 用 StringBuilder 类替代 String
- · 杂志目录(页面部分CodeBehind)
- · 杂志目录(数据库访问部分)
- · 杂志目录(页面部分)
- · 推荐一个免费的CSharp编辑器
- · 使用JScript.NET创建asp.net页面(二)
- · 使用JScript.NET创建asp.net页面(三)
- · 使用JScript.NET创建asp.net页面(四)
- · 使用JScript.NET创建asp.net页面(五)
- · 使用JScript.NET创建asp.net页面(六)
DPC:Creating a DataBound List of Radio Buttons--预览页面source code[等级:中]
<% @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>
下一篇:.NET几大热点问题(转) >>
相关文章:
- · 使用JScript.NET创建asp.net页面(七)
- · 有好东西不要自己藏着,拿出来大家分享啊,这是我的:关于bate2的MD5加密方法.
- · 转:ASP.NET验证控件详解
- · 在ASP.NET中获取文件属性
- · datalist分页(codebehind部分)
- · datalist分页(cj168.DataAccess.MagsDB中的2个方法)
- · datalist分页(页面部分)
- · .net beta2 操作cookie的例子(转)
- · 如何在DataGrid控件中隐藏列
- · Common ASP.NET Code Techniques (DPC&DWCReference)--1
- · Common ASP.NET Code Techniques (DPC&dwc Reference)--2
- · Common ASP.NET Code Techniques (DPC&DWC Reference)--3
- · Common ASP.NET Code Techniques (DPC&DWC Reference)--4
- · Common ASP.NET Code Techniques (DPC&DWC Reference)--5
- · Common ASP.NET Code Techniques (DPC&DWC Reference)--6
- · 在datagrid中删除时确定(精华区的补充)
- · Displaying ListView items - with class! by Rob Birdwell
- · 一个带checkbox的webcontrol
- · 保护 XML Web 服务免受黑客攻击 [第一部分]
- · 保护 XML Web 服务免受黑客攻击, [第二部分]
- · treeview的源代码
- · 在datagrid中删除时确定?(转)
- · vs.net beta 2中利用DataGrid分页详解
- · COM组件对象与.NET类对象的相互转换
- · 关于DataGrid对象的属性设置(VB)
- · XmlNodeList
- · 用 FormsAuthentication.SetAuthCookie 做权限验证
- · 在datalist中选取数据。
- · Finding a Control Inside a Template
- · DataBinding DropDownList
- · 用asp.net向其他服务器post一条信息
- · Asp.net中用核选框显示数据的方法及ButtonColumn的使用方法
- · 如何在DataGrid控件中实现编辑、删除、分类以及分页操作
- · .NET框架类览胜( Ccident Net )
- · 使用JScript.NET创建asp.net页面(一)
- · 用Visual C#获得计算机名称和IP地址(转)
- · 据说可能是介绍 web.config 最详细的文章。大家参考参考[转]
- · 在ASP.NET中使用Session与Application 对象
