asp:DropDownList与asp:DataList的联合使用
2016-04-29 21:22
543 查看
[b]情况:当在asp:DropDownLis点击选取其中的一个值来响应datalist的值。[/b]
<form id="form1" runat="server">
<div>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:examConnectionString2 %>" SelectCommand="SELECT * FROM [Students]"></asp:SqlDataSource>
//DropDownList连接SqlDataSource2
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource2"
DataTextField="StudentName" DataValueField="StudentNo" AutoPostBack="True">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:examConnectionString %>"
SelectCommand="select sub.SubjectNo,SubjectName,sub.SubjectKind,sub.Credit,sc.Score from Subjects sub,Score sc where sc.StudentNo = @StudentNo and sc.SubjectNo=sub.SubjectNo">
<SelectParameters>
//通过SqlDataSource1连接[b]DropDownList[/b]
<asp:ControlParameter ControlID="DropDownList1" DefaultValue="1" Name="StudentNo" PropertyName="SelectedValue"
Type="String" />
</SelectParameters>
</asp:SqlDataSource>
//datalist连接SqlDataSource1
<asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1">
<HeaderTemplate>
<table id="tblist">
<tr>
<th>课程编号</th>
<th>课程名</th>
<th>课程类别</th>
<th>学分</th>
<th>成绩</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:Label ID="SubjectNoLabel" runat="server" Text='<%# Eval("SubjectNo") %>' />
</td>
<td>
<asp:Label ID="SubjectNameLabel" runat="server" Text='<%# Eval("SubjectName") %>' />
</td>
<td>
<asp:Label ID="SubjectKindLabel" runat="server" Text='<%# Eval("SubjectKind") %>' />
</td>
<td>
<asp:Label ID="CreditLabel" runat="server" Text='<%# Eval("Credit") %>' />
</td>
<td>
<asp:Label ID="ScoreLabel" runat="server" Text='<%# Eval("Score") %>' />
</td>
</tr>
</ItemTemplate>
<FooterTemplate></table></FooterTemplate>
</asp:DataList>
</div>
</form>
</body>
</html>
<form id="form1" runat="server">
<div>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:examConnectionString2 %>" SelectCommand="SELECT * FROM [Students]"></asp:SqlDataSource>
//DropDownList连接SqlDataSource2
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource2"
DataTextField="StudentName" DataValueField="StudentNo" AutoPostBack="True">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:examConnectionString %>"
SelectCommand="select sub.SubjectNo,SubjectName,sub.SubjectKind,sub.Credit,sc.Score from Subjects sub,Score sc where sc.StudentNo = @StudentNo and sc.SubjectNo=sub.SubjectNo">
<SelectParameters>
//通过SqlDataSource1连接[b]DropDownList[/b]
<asp:ControlParameter ControlID="DropDownList1" DefaultValue="1" Name="StudentNo" PropertyName="SelectedValue"
Type="String" />
</SelectParameters>
</asp:SqlDataSource>
//datalist连接SqlDataSource1
<asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1">
<HeaderTemplate>
<table id="tblist">
<tr>
<th>课程编号</th>
<th>课程名</th>
<th>课程类别</th>
<th>学分</th>
<th>成绩</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:Label ID="SubjectNoLabel" runat="server" Text='<%# Eval("SubjectNo") %>' />
</td>
<td>
<asp:Label ID="SubjectNameLabel" runat="server" Text='<%# Eval("SubjectName") %>' />
</td>
<td>
<asp:Label ID="SubjectKindLabel" runat="server" Text='<%# Eval("SubjectKind") %>' />
</td>
<td>
<asp:Label ID="CreditLabel" runat="server" Text='<%# Eval("Credit") %>' />
</td>
<td>
<asp:Label ID="ScoreLabel" runat="server" Text='<%# Eval("Score") %>' />
</td>
</tr>
</ItemTemplate>
<FooterTemplate></table></FooterTemplate>
</asp:DataList>
</div>
</form>
</body>
</html>
相关文章推荐
- 【asp.net】控件
- ASP.NET MVC 网站开发总结(三) ——图片截图上传
- asp.net MVC 中 Session统一验证的方法
- ASPxGridView 导出和部分属性设置
- 1.简单实例:ASP.NET下Echarts通过Ajax从数据库中获取数据
- CS0016: 未能写入输出文件“c:/Windows/Microsoft.NET/Framework/v2.0.50727/Temporary ASP.NET Files/root/...拒绝访问
- 未能将网站xx 配置为使用 ASP.NET 4.0。为了使此网站正确运行,您必须将它手动配置为使用 ASP.NET 4.0。
- asp.net 配置 web.config 禁用VS2013自带的Browser Link功能
- java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldException
- 【Raspberry Pi 3试用体验】+ngrok 内网穿透
- ireport/jasprereport studio 导出excel最后有空白行
- 【Raspberry Pi 3试用体验】+ 使用owncloud云服务
- ASP.NET 状态管理(视图状态 ViewState)
- 了解ASP.NET MVC几种ActionResult的本质:EmptyResult & ContentResult
- 了解ASP.NET MVC几种ActionResult的本质:FileResult
- ASP.NET5使用FaceBook登录
- Aspose word导出照片代码实现
- Asp.net下使用RequiredFieldValidator影响别的控件的问题
- ASP.NET MVC中错误日志信息记录
- ASP.NET MVC异步处理请求的意义