make(使用SqlDataSource中的FilterExpression使用DropDownList进行GridView)无需使用JavaScript重新加载页面即可运行

时间:2014-11-15 09:27:41

标签: javascript asp.net gridview filtering sqldatasource

如何在不使用JavaScript重新加载页面的情况下(使用SqlDataSource中的FilterExpression过滤GridView与DropDownList)?

<asp:DropDownList ID="ddlCountries" runat="server" AutoPostBack="True" DataSourceID="DropDownDataSource"
    DataTextField="SC" DataValueField="SC" AppendDataBoundItems="True">
    <asp:ListItem Text="All " Value="" />
</asp:DropDownList>

<asp:SqlDataSource ID="DropDownDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:CountConnectionString %>"
    SelectCommand="SELECT [SC] FROM [CountTable]"></asp:SqlDataSource>

<asp:GridView ID="GridView1" HeaderStyle-BackColor="#3AC0F2" HeaderStyle-ForeColor="White"
    runat="server" AutoGenerateColumns="False" DataSourceID="GridDataSource" 
        DataKeyNames="ID">
    <Columns>
        <asp:BoundField DataField="ID" HeaderText="ID" ItemStyle-Width="150" 
            InsertVisible="False" ReadOnly="True" SortExpression="ID" />
        <asp:BoundField DataField="SC" HeaderText="SC" ItemStyle-Width="150" 
            SortExpression="SC" />
        <asp:BoundField DataField="Traffic" HeaderText="Traffic" 
            SortExpression="Traffic" />
    </Columns>

<HeaderStyle BackColor="#3AC0F2" ForeColor="White"></HeaderStyle>
</asp:GridView>

<asp:SqlDataSource ID="GridDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:CountConnectionString %>"
    SelectCommand="SELECT * FROM [CountTable]" FilterExpression="SC = '{0}'">
    <FilterParameters>
        <asp:ControlParameter Name="SC" ControlID="ddlCountries" PropertyName="SelectedValue" />
    </FilterParameters>
</asp:SqlDataSource>

0 个答案:

没有答案