modify SqlDataSource parameters in code behind?

G

Guest

I have a TextBox used to enter a search value and a DropDownList used to
select which field should be searched on. I need to load a GridView with the
search results.

I have setup multiple select stored procedures and need to set the
SqlDataSource to use the required stored procedure and pass the value in the
TextBox to search with.

The following code sets up the SelectParameters for the SqlDataSource:
RegistrantsSqlDataSource.SelectParameters.Clear();
switch(selectionChoice){ // from DropDownList
case "Name":
Session["SelectCommand"] = "GetRegListbyName";
RegistrantsSqlDataSource.SelectParameters.Add( "Name",
TypeCode.String.ToString());
break;
case "Phone":
Session["SelectCommand"] = "GetRegListbyPhone";
RegistrantsSqlDataSource.SelectParameters.Add( "Phone",
TypeCode.String.ToString());
break;
etc...
I don't know how to pass the search value from the TextBox to the
SqlDataSource which the GridView is bound to.

Any suggestions would be appreciated, I'm going crosseyed looking at this.
 
G

Guest

The syntax in the codebehind:
RegistrantsSqlDataSource.SelectParameters["Name"].DefaultValue =
txtSearchKeyWord.Text;

The declarative syntax:
<SelectParameters>
<asp:ControlParameter ControlID="txtSearchKeyWord" Name="SearchKeyWord"
PropertyName="Text" />
<asp:ControlParameter ControlID="ddlSearchCategory" Name="Category"
PropertyName="SelectedValue" />
</SelectParameters>
 
G

Guest

Thanks so much.. I was going batty, and I thought this propery was for a
value if you didn't have a value to set. I also forgot to set the
SelectCommandType. But it all works now!


Phillip Williams said:
The syntax in the codebehind:
RegistrantsSqlDataSource.SelectParameters["Name"].DefaultValue =
txtSearchKeyWord.Text;

The declarative syntax:
<SelectParameters>
<asp:ControlParameter ControlID="txtSearchKeyWord" Name="SearchKeyWord"
PropertyName="Text" />
<asp:ControlParameter ControlID="ddlSearchCategory" Name="Category"
PropertyName="SelectedValue" />
</SelectParameters>
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


Dabbler said:
I have a TextBox used to enter a search value and a DropDownList used to
select which field should be searched on. I need to load a GridView with the
search results.

I have setup multiple select stored procedures and need to set the
SqlDataSource to use the required stored procedure and pass the value in the
TextBox to search with.

The following code sets up the SelectParameters for the SqlDataSource:
RegistrantsSqlDataSource.SelectParameters.Clear();
switch(selectionChoice){ // from DropDownList
case "Name":
Session["SelectCommand"] = "GetRegListbyName";
RegistrantsSqlDataSource.SelectParameters.Add( "Name",
TypeCode.String.ToString());
break;
case "Phone":
Session["SelectCommand"] = "GetRegListbyPhone";
RegistrantsSqlDataSource.SelectParameters.Add( "Phone",
TypeCode.String.ToString());
break;
etc...
I don't know how to pass the search value from the TextBox to the
SqlDataSource which the GridView is bound to.

Any suggestions would be appreciated, I'm going crosseyed looking at this.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top