<% @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 publishers 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>
DPC:Creating a DataBound List of Radio Buttons–预览页面source code[等级:中]-.NET教程,Asp.Net开发
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » DPC:Creating a DataBound List of Radio Buttons–预览页面source code[等级:中]-.NET教程,Asp.Net开发
相关推荐
-      VS2010的aspx文件中的html代码的格式化方法
-      .net 反序题目的详细解答第1/2页
-      asp.net创建html文本文件实例
-      比较完整的 asp.net 学习流程
-      C# XML操作 代码大全(读XML,写XML,更新,删除节点,与dataset结合等)第1/2页
-      官网 Ext direct包中.NET版的问题
-      c# 连接字符串数据库服务器端口号 .net状态服务器端口号
-      asp.net教程:简单的C#图片上传代码或C#文件上传代码
