我想为我的标题列 [Carrier] 之一创建一个过滤器,这是我创建的 gridview 的代码:
索引.aspx:
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="cr_OnSelectedIndexChanged"
DataSourceID="SqlDataSource1" DataTextField="CARRIER" DataValueField="CARRIER">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:MybaseConnectionString %>"
SelectCommand="SELECT DISTINCT [CARRIER] FROM [TABLE]">
</asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" Height="150px" Width="284px">
</asp:GridView>
索引.aspx.vb
Inherits System.Web.UI.Page
Dim cx As New SqlConnection("Data Source=.\SQLEXPRESS;database=Mybase;Integrated Security=True;")
Dim cmd As New SqlCommand
Dim da As New SqlDataAdapter
Dim dt As New DataTable
Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
cmd.Connection = cx
cmd.CommandText = "select cl1, Carrier, cl2, cl3 from table"
da = New SqlDataAdapter(cmd)
da.Fill(dt)
GridView1.DataSource = dt
GridView1.DataBind()
End Sub
Protected Sub DropDownList1_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
End Sub
任何人都可以帮助请!谢谢..