Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Dec 05, 2012 03:53 AM by Decker Dong - MSFT
0 Points
8 Posts
Dec 04, 2012 02:59 PM|LINK
Hello I'm using the folowing Datasource for a datagridview:
<asp:SqlDataSource ID="datasource" runat="server" ConnectionString="<%$ ConnectionStrings:connString%>" //... SelectCommand="select [...] from [...] where Field1 = @PARA1"> <SelectParameters> <asp:ControlParameter ControlID="dropwDownList1" Name="PARA1" PropertyName="SelectedValue" /> </SelectParameters> </asp:SqlDataSource>
This dropdownlist should filter the selection. it has the following values: (-1,0,1,2...)
-1 stands in text for : no filter.
in this case i want no where condition. how can i do this in the ASP file?
Participant
797 Points
180 Posts
Dec 04, 2012 03:14 PM|LINK
I would suggest storing your select command in a string:
string selectString = "select [...] from [...]";
then check dropDownList1.SelectedValue.
if (dropDownList1.SelectedValue != -1)
{
selectString += " where Field1 = @Para1";
}
Then set your SqlCommand and parameters in the code behind, again checking ddl.selectedValue before adding the parameter.
All-Star
118619 Points
18779 Posts
Dec 05, 2012 03:53 AM|LINK
BStefan BStefan
Hi,
If you wanna dynamically create a SQL query filtering, I suggest you trying to use manually databinding instead of use the DataSource. Generally speaking, a DataSource is usually used for a fixed query string.
BStefan
0 Points
8 Posts
Use SqlDatasource Parameters with condition
Dec 04, 2012 02:59 PM|LINK
Hello I'm using the folowing Datasource for a datagridview:
<asp:SqlDataSource ID="datasource" runat="server" ConnectionString="<%$ ConnectionStrings:connString%>" //... SelectCommand="select [...] from [...] where Field1 = @PARA1"> <SelectParameters> <asp:ControlParameter ControlID="dropwDownList1" Name="PARA1" PropertyName="SelectedValue" /> </SelectParameters> </asp:SqlDataSource>This dropdownlist should filter the selection. it has the following values: (-1,0,1,2...)
-1 stands in text for : no filter.
in this case i want no where condition. how can i do this in the ASP file?
msmk
Participant
797 Points
180 Posts
Re: Use SqlDatasource Parameters with condition
Dec 04, 2012 03:14 PM|LINK
I would suggest storing your select command in a string:
string selectString = "select [...] from [...]";
then check dropDownList1.SelectedValue.
if (dropDownList1.SelectedValue != -1)
{
selectString += " where Field1 = @Para1";
}
Then set your SqlCommand and parameters in the code behind, again checking ddl.selectedValue before adding the parameter.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Use SqlDatasource Parameters with condition
Dec 05, 2012 03:53 AM|LINK
Hi,
If you wanna dynamically create a SQL query filtering, I suggest you trying to use manually databinding instead of use the DataSource. Generally speaking, a DataSource is usually used for a fixed query string.