zoukankan      html  css  js  c++  java
  • asp:DropDownList与asp:DataList的联合使用

    情况:当在asp:DropDownLis点击选取其中的一个值来响应datalist的值。

    <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连接DropDownList
    <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>

  • 相关阅读:
    C#低级Windows API钩子拦截键盘输入
    PowerDesigner 11 使用心得
    c# windows服务状态、启动和停止服务
    PowerDesigner设计数据库
    C# Windows帐户和目录添加用户权限方法
    ASP.NET的控件Gridview在Firefox中的Border显示问题
    去掉图片连接的虚框
    http://www.ediyang.com/demo/DD_Png/
    WEB前端开发规范文档(for: mrthink.net)
    .net下载文件的常用方法汇总
  • 原文地址:https://www.cnblogs.com/tandy/p/5447600.html
Copyright © 2011-2022 走看看