Hello Experts,

First I want to thank you all.I am getting all responses at this Daniweb :)

My problem is that I have a sql statement where I want to add where clause in case of dropdown is changed.

My database connection part:

<asp:AccessDataSource ID="AccessDataSource1" runat="server" 
            DataFile="~/_database.accdb" 
            SelectCommand="SELECT * FROM [Devices] WHERE ([feature1] = ?)">

but I don't want that * WHERE ([feature1] = ?) * exist there.

I want that it only added there when i click to the below radio button

<asp:RadioButtonList ID="feature1" runat="server" AutoPostBack="True" 
            DataSourceID="AccessDataSource10" DataTextField="feature1" 
            DataValueField="feature1">
        </asp:RadioButtonList>

As far as I understand I should write some

RadioButton Control OnCheckedChanged Event and some code in the select command part within the sql but I don't know how i will do that or is it doable within the sql statement part ?

I found the solution,here it is: it's called multivalue parameter.

Create a dataset for selecting the Key and Label for available supervisors.
Create a parameter @SupervisorIDs with the first dataset as available values.
Set the parameter to "Allow multiple values".
Create your second dataset that retrieves the actual results
In the second dataset, create a filter like this: WHERE SuperVisorId IN (@SupervisorIDs)
Reporting services will replace the parameter inside the WHERE clause dynamically with a comma seperated list with the values your user has selected, before sending the query to SQL Server.

here is more information: Click Here

Edit:Actually not %100 that i am looking for it's not dynamically adding where clause within the sql statement :( any suggestions ?

So you want to query all records, unless a selection is made in the drop down list? hmm.. so I may have approached this a different way.

I'm not completely following your last post, but let me show you an example, and see if this is helpful or possibly give you an idea.

I have a drop down and a gridview control. My drop down looks like this...

<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
  <asp:ListItem  Selected="True" Value="%">-- Select  --</asp:ListItem>
  <asp:ListItem>One</asp:ListItem>
  <asp:ListItem>Two</asp:ListItem>
  <asp:ListItem>Three</asp:ListItem>
</asp:DropDownList>

Now, I have a gridview. it uses the selected value for querying my data source, a SQL DB table.

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="SqlDataSource1" >
  <Columns>
    <asp:BoundField DataField="field1" HeaderText="field1" SortExpression="field1" />
  </Columns>
</asp:GridView>

data source...

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:DB %>" SelectCommand="SELECT * FROM [Table] WHERE ([Field1] LIKE @field1)">
 <SelectParameters>
  <asp:ControlParameter ControlID="DropDownList1" DefaultValue="%" Name="Field1" PropertyName="SelectedValue" Type="String" />
 </SelectParameters>
</asp:SqlDataSource>

If the user does not select a value from my dropdown, i get all of the records in the table. If the user selects a value, the change in the dropdown generates an autopost back and now my query will result in returing only values that match the value selected.

please note these code examples were written by hand from memory so they may not work if you simply copy and paste into your project.

Thank you JorgeM that's working perfect :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.