有这样一个功能,根据checkboxlist的选择,可以选择多个,然后根据选择的条件的不同,gridview显示不同的信息。
可能需要用到动态添加列,可是不知道怎么实现,那位高手帮帮忙,给点高见。小弟先谢谢了!
比如:选择了A 班,B班两个,gridview 里从数据库读出两个班的信息,然后显示出来。也就是做个对比。
可能需要用到动态添加列,可是不知道怎么实现,那位高手帮帮忙,给点高见。小弟先谢谢了!
比如:选择了A 班,B班两个,gridview 里从数据库读出两个班的信息,然后显示出来。也就是做个对比。
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:SqlDataSource ID="categoryDS" runat="server" ConnectionString="<%$ConnectionStrings:categoryConnectionString %>" SelectCommand="select categoryid,categoryName from categories"></asp:SqlDataSource>
<asp:DropDownList ID="list" runat="server" DataSourceID="categoryDS" DataTextField="categoryName" DataValueField="categoryid" AutoPostBack="True" OnSelectedIndexChanged="list_SelectedIndexChanged"></asp:DropDownList>
<asp:Label ID="lab1" runat="server"></asp:Label>
<br />
<br />
<br />
<br />
<asp:Label ID="Label1" runat="server" Text="<%$ ConnectionStrings:labelContent %>" Width="184px"></asp:Label><br />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="ProductID" DataSourceID="ProductDS">
<Columns>
<asp:BoundField DataField="ProductID" HeaderText="ProductID" InsertVisible="False"
ReadOnly="True" SortExpression="ProductID" />
<asp:BoundField DataField="ProductName" HeaderText="ProductName" SortExpression="ProductName" />
<asp:BoundField DataField="SupplierID" HeaderText="SupplierID" SortExpression="SupplierID" />
<asp:BoundField DataField="CategoryID" HeaderText="CategoryID" SortExpression="CategoryID" />
</Columns>
</asp:GridView>
<br />
<asp:SqlDataSource ID="ProductDS" runat="server" ConnectionString="<%$ ConnectionStrings:northwindConnectionString %>" SelectCommand="SELECT [ProductID], [ProductName], [SupplierID], [CategoryID] FROM [Products] WHERE ([CategoryID] = @CategoryID)">
<SelectParameters>
<asp:ControlParameter ControlID="list" Name="CategoryID" PropertyName="SelectedValue"
Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
</div>
</form>
</body>
</html>
2、通过自动挥发,编写一个方法:1)foreach 遍历checkboxlist中哪些备选中 2)取出被选中的对应ID
3)连接数据库,利用迭代for select * from class where ID=i 执行,取出添加到dataset中
4)再绑定gridview