有这样一个功能,根据checkboxlist的选择,可以选择多个,然后根据选择的条件的不同,gridview显示不同的信息。
可能需要用到动态添加列,可是不知道怎么实现,那位高手帮帮忙,给点高见。小弟先谢谢了!
比如:选择了A 班,B班两个,gridview 里从数据库读出两个班的信息,然后显示出来。也就是做个对比。

解决方案 »

  1.   

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Model9_ADO_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
    <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.   

    你可以当checkboxlist changing时 在你gridview 帮定的dataset 或datatable里Insert()数据  在绑定新的数据源
      

  3.   

    1、首先你的数据库 要设计好,主键ID号 与checkboxlist 对应起来。
    2、通过自动挥发,编写一个方法:1)foreach 遍历checkboxlist中哪些备选中 2)取出被选中的对应ID
       3)连接数据库,利用迭代for   select * from class where ID=i  执行,取出添加到dataset中
       4)再绑定gridview
      

  4.   

    那个for 循环怎么写?能不能给点代码?谢了!