469,957 Members | 2,689 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,957 developers. It's quick & easy.

modify SqlDataSource parameters in code behind?

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.
Apr 4 '06 #1
2 14574
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" wrote:
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.

Apr 4 '06 #2

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" wrote:
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" wrote:
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.

Apr 4 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Martin Bischoff | last post: by
1 post views Thread by staeri | last post: by
3 posts views Thread by Dorte | last post: by
reply views Thread by rainxy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.