locked
FilterParameters with DropDownList and TextBox RRS feed

  • Question

  • User1432602220 posted

    Hello,

    I have a filtered GridView thanks to some DropDownList and a TextBox.

    I put the autopostback to true for DropDownList to filter the GridView and I have a textBox and a button to filter the content of the GridView.

    The problem is : when I search something with a TextBox, it works fine. But if I just want to use DropDownList to filter the GridView (and not the TextBox), it doesn't works.

    The SQLDatasource code and the filtered GirdView to better understand :

    <asp:GridView ID="GridView1" Width="100%" Height="100%" HeaderStyle-BackColor="#e80616"
                        HeaderStyle-ForeColor="White" runat="server" AutoGenerateColumns="false" DataSourceID="GridDataSource"
                        ShowHeader="true">
                        <Columns>
                            <asp:BoundField DataField="ObjectifStrategique" HeaderText="Objectif stratégique"
                                ItemStyle-Width="120" ItemStyle-HorizontalAlign="Left" HtmlEncode="false" />
                            <asp:BoundField DataField="ObjectifOperationnel" HeaderText="Objectif Opérationnel"
                                ItemStyle-Width="120" ItemStyle-HorizontalAlign="Left" HtmlEncode="false" />
                            <asp:BoundField DataField="RefAct" HeaderText="Réf.Activité" ItemStyle-Width="30px"
                                ItemStyle-HorizontalAlign="Left" HtmlEncode="false" />
                            <asp:BoundField DataField="DescriptionActivite" HeaderText="Description activité"
                                ItemStyle-Width="180" ItemStyle-HorizontalAlign="Left" HtmlEncode="false" />
                            <asp:BoundField DataField="Debut" HeaderText="Début" ItemStyle-Width="30px" HtmlEncode="false" />
                            <asp:BoundField DataField="Fin" HeaderText="Fin" ItemStyle-Width="30px" HtmlEncode="false" />
                            <asp:BoundField DataField="Nom" HeaderText="Chef de file" ItemStyle-Width="120" ItemStyle-HorizontalAlign="Left"
                                HtmlEncode="false" />
                            <asp:BoundField DataField="Livrables" HeaderText="Livrables" ItemStyle-Width="120"
                                ItemStyle-HorizontalAlign="Left" HtmlEncode="false" />
                        </Columns>
                    </asp:GridView>
    <asp:SqlDataSource ID="GridDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:connexionBase %>"
                    SelectCommand="SELECT [Nom], [RefAct], [Entite], [Origine], [ObjectifStrategique], [Cle], [MAP], [SNS], [ObjectifOperationnel], [DescriptionActivite], [Debut], [Fin], [Livrables], [Annee], [ID] FROM reponse"
                    FilterExpression="Nom like '%{0}%' AND Entite like '%{1}%' AND Origine like '%{2}%' AND ObjectifStrategique like '%{3}%' AND Cle like '%{4}%' AND MAP like '%{5}%' AND SNS like '%{6}%' AND Annee = {7} AND RefAct LIKE '%{8}%'">
                    <FilterParameters>
                        <asp:ControlParameter Name="Nom" ControlID="NomPersonne" PropertyName="SelectedValue"
                            ConvertEmptyStringToNull="false" />
                        <asp:ControlParameter Name="Entite" ControlID="NomEntite" PropertyName="SelectedValue"
                            ConvertEmptyStringToNull="false" />
                        <asp:ControlParameter Name="Origine" ControlID="ContenuOrigine" PropertyName="SelectedValue"
                            ConvertEmptyStringToNull="false" />
                        <asp:ControlParameter Name="ObjectifStrategique" ControlID="Objectif_strategique"
                            PropertyName="SelectedValue" ConvertEmptyStringToNull="false" />
                        <asp:ControlParameter Name="Cle" ControlID="Key" PropertyName="SelectedValue" ConvertEmptyStringToNull="false" />
                        <asp:ControlParameter Name="MAP" ControlID="map1" PropertyName="SelectedValue" ConvertEmptyStringToNull="false" />
                        <asp:ControlParameter Name="SNS" ControlID="sns1" PropertyName="SelectedValue" ConvertEmptyStringToNull="false" />
                        <asp:ControlParameter Name="Annee" ControlID="year" PropertyName="SelectedValue"
                            ConvertEmptyStringToNull="false" />
                        <asp:ControlParameter Name="RefAct" ControlID="txtSearch" PropertyName="Text" />
                    </FilterParameters>
                </asp:SqlDataSource>

    Thanks for your help !

    Friday, July 18, 2014 6:57 AM

Answers

  • User-1360095595 posted

    I'm not sure, but try adding DefaultValue="".

    Alternatively, run a SQL trace on the database and check what SQL is being sent. It might provide some insight.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, July 18, 2014 8:58 AM
  • User1918509225 posted

    Hi RedBox77,

    As soon as some item is selected in the DropDownList the GridView records are filtered,

    this happens because we have set AutoPostBack property to true for the DropDownList,

    if this property is not set then the GridView records will not be refreshed and filtered.

    Best Regards,

    Kevin Shen.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 21, 2014 4:50 AM

All replies

  • User-1360095595 posted

    I'm not sure, but try adding DefaultValue="".

    Alternatively, run a SQL trace on the database and check what SQL is being sent. It might provide some insight.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, July 18, 2014 8:58 AM
  • User1432602220 posted

    Where should I put it ?

    Friday, July 18, 2014 2:48 PM
  • User-1360095595 posted

    On the controlparameter.

    Friday, July 18, 2014 3:30 PM
  • User1432602220 posted

    It's the same thing :/

    Sunday, July 20, 2014 9:09 AM
  • User1918509225 posted

    Hi RedBox77,

    As soon as some item is selected in the DropDownList the GridView records are filtered,

    this happens because we have set AutoPostBack property to true for the DropDownList,

    if this property is not set then the GridView records will not be refreshed and filtered.

    Best Regards,

    Kevin Shen.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 21, 2014 4:50 AM
  • User1432602220 posted

    I removed the AutoPostback and put DefaultValue in ControlParameter of the Button Search.

    Now when I choose a value of a DropDownList and I click on Search, it doesn't work. 

    But when I choose a value of DropDown and I put a value of the textBox Search, it works.

    EDIT : Now it works, I put DefaultValue to 0.

    Monday, July 21, 2014 7:40 AM