下拉列表填充gridview

时间:2015-11-30 17:23:18

标签: c# asp.net datagridview

我在Visual Studio中使用向导来定义填充下拉列表的数据源。这工作正常。然后我有第二个数据源,它应该使用下拉列表中的选定值过滤来自另一个表的数据,并将其显示在gridview中。当我在下拉列表中进行选择时,我认为gridview应该自动更改以显示新的过滤数据。但事实并非如此。好像我错过了一个自动回帖或类似的东西。以下是我正在使用的代码。

<form id="appointmentform" runat="server">

<div class="wdn-band" id="findpersonband" runat="server" visible="true">
    <div class="wdn-inner-wrapper wdn-inner-padding-sm">
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:SNR_InformationConnectionString %>" SelectCommand="SELECT [personnelid], [lastname] FROM [tblmasterpersonnel] ORDER BY [lastname], [preferredfirstname]"></asp:SqlDataSource>
    <asp:DropDownList ID="MasterPersonnelDDL" runat="server" DataSourceID="SqlDataSource1" DataTextField="lastname" DataValueField="personnelid"></asp:DropDownList>
    <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:SNR_InformationConnectionString %>" SelectCommand="SELECT [personnelid], [startdate], [endingdate], [employeetypeid], [dateentered] FROM [tblappointmentdate] WHERE ([personnelid] = @personnelid)">
        <SelectParameters>
            <asp:ControlParameter ControlID="MasterPersonnelDDL" Name="personnelid" PropertyName="SelectedValue" Type="Int32" />
        </SelectParameters>
    </asp:SqlDataSource>
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource2">
        <Columns>
            <asp:BoundField DataField="startdate" HeaderText="startdate" SortExpression="startdate" />
            <asp:BoundField DataField="endingdate" HeaderText="endingdate" SortExpression="endingdate" />
            <asp:BoundField DataField="employeetypeid" HeaderText="employeetypeid" SortExpression="employeetypeid" />
            <asp:BoundField DataField="dateentered" HeaderText="dateentered" SortExpression="dateentered" />
        </Columns>
    </asp:GridView>
</div>
</div>
</form>

感谢您的帮助

1 个答案:

答案 0 :(得分:0)

可能是你可以使用

<asp:DropDownList ID="MasterPersonnelDDL" runat="server" DataSourceID="SqlDataSource1" DataTextField="lastname" DataValueField="personnelid" AutoPostBack="True"></asp:DropDownList>