我创建了一个名为 Ztv.mdf 的数据库,表为 tabl1,带有 [Name], [fullname], [Id],[dept]& 还为 dept 创建了一个下拉列表 1。当用户从下拉列表 1 中选择了 dept 值时gridview 显示输出。它工作正常。但我想要 1 个名称的下拉列表。我的目标是,当用户从下拉列表 1 和下拉列表 2 中选择值时,它控制网格视图。我该怎么做?
我的 1 个下拉列表和网格视图的代码是:
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="ddlSearchCriteria" runat="server"
DataSourceID="SqlDataSource1" DataTextField="depat" DataValueField="Id"
AutoPostBack="True">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ztvConnectionString %>"
SelectCommand="SELECT [Id], [depat] FROM [Table1]"></asp:SqlDataSource>
<br />
<asp:GridView ID="gvSearchResults" runat="server" AutoGenerateColumns="False"
DataKeyNames="Id" DataSourceID="SqlDataSource2" CellPadding="4"
ForeColor="#333333" GridLines="None" style="margin-left: 155px">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:BoundField DataField="Id" HeaderText="Id" InsertVisible="False"
ReadOnly="True" SortExpression="Id" />
<asp:BoundField DataField="fullname" HeaderText="fullname"
SortExpression="fullname" />
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:ztvConnectionString %>"
SelectCommand="SELECT [Name], [fullname], [Id] FROM [Table1] WHERE ([Id] = @Id)">
<SelectParameters>
<asp:ControlParameter ControlID="ddlSearchCriteria" Name="Id"
PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<br />
<br />
<br />
</div>
</form>