473,762 Members | 7,330 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 SelectParameter s for the SqlDataSource:
RegistrantsSqlD ataSource.Selec tParameters.Cle ar();
switch(selectio nChoice){ // from DropDownList
case "Name":
Session["SelectComm and"] = "GetRegListbyNa me";
RegistrantsSqlD ataSource.Selec tParameters.Add ( "Name",
TypeCode.String .ToString());
break;
case "Phone":
Session["SelectComm and"] = "GetRegListbyPh one";
RegistrantsSqlD ataSource.Selec tParameters.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 14809
The syntax in the codebehind:
RegistrantsSqlD ataSource.Selec tParameters["Name"].DefaultValue =
txtSearchKeyWor d.Text;

The declarative syntax:
<SelectParamete rs>
<asp:ControlPar ameter ControlID="txtS earchKeyWord" Name="SearchKey Word"
PropertyName="T ext" />
<asp:ControlPar ameter ControlID="ddlS earchCategory" Name="Category"
PropertyName="S electedValue" />
</SelectParameter s>
--
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 SelectParameter s for the SqlDataSource:
RegistrantsSqlD ataSource.Selec tParameters.Cle ar();
switch(selectio nChoice){ // from DropDownList
case "Name":
Session["SelectComm and"] = "GetRegListbyNa me";
RegistrantsSqlD ataSource.Selec tParameters.Add ( "Name",
TypeCode.String .ToString());
break;
case "Phone":
Session["SelectComm and"] = "GetRegListbyPh one";
RegistrantsSqlD ataSource.Selec tParameters.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
SelectCommandTy pe. But it all works now!
"Phillip Williams" wrote:
The syntax in the codebehind:
RegistrantsSqlD ataSource.Selec tParameters["Name"].DefaultValue =
txtSearchKeyWor d.Text;

The declarative syntax:
<SelectParamete rs>
<asp:ControlPar ameter ControlID="txtS earchKeyWord" Name="SearchKey Word"
PropertyName="T ext" />
<asp:ControlPar ameter ControlID="ddlS earchCategory" Name="Category"
PropertyName="S electedValue" />
</SelectParameter s>
--
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 SelectParameter s for the SqlDataSource:
RegistrantsSqlD ataSource.Selec tParameters.Cle ar();
switch(selectio nChoice){ // from DropDownList
case "Name":
Session["SelectComm and"] = "GetRegListbyNa me";
RegistrantsSqlD ataSource.Selec tParameters.Add ( "Name",
TypeCode.String .ToString());
break;
case "Phone":
Session["SelectComm and"] = "GetRegListbyPh one";
RegistrantsSqlD ataSource.Selec tParameters.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
4480
by: Martin Bischoff | last post by:
Hi, is it possible to modify the values of a SqlDataSource's select parameters in the code behind before the select command is executed? Example: I have an SqlDataSource with a ControlParameter <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:XYZ %>"
1
1895
by: staeri | last post by:
Hello! I would like to set the SqlDataSource in the code behind file and not to have it in the aspx file. How can I do that? Regards, Staeri
3
12734
by: Dorte | last post by:
Hi, Could someone help me with a couple of links to SqlDatasource documentation on how to use the Gridview and SqlDatasource components in code behind? Basically I'm missing some documentation on how to handle different tasks programmatically such as selects, updates, sorting of data etc. in code behind if I prefer to set all Gridview and Sqldatasource properties etc. in code behind rather than in the aspx file.
2
19794
by: phil | last post by:
Hi, I want to put a recordset in a gridview but i don't know how to pass the value of the variable in the 'where' statement. The value of the variable is set in the code-behind. i added a tag <selectParameters> but i don't know which elements are needed and how... This is my aspx file: <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\mydb.mdb"
0
1013
by: Kel | last post by:
I am currently trying to pass the SqlDataSource below a paramter set in the code-behind (C#) My stored procedure takes one parameter @AID varchar(25). <asp:SqlDataSource ID="ListEmpSource" Runat="server" SelectCommand="dbo.usp_ListEmps" ConnectionString="Server=(local);Database=Test;Trusted_Connection=yes" SelectCommandType="StoredProcedure" >
1
12323
by: John Bailo | last post by:
This is a my solution to getting an Output parameter from a SqlDataSource. I have seen a few scant articles but none of them take it all the way to a solution. Hopefully this will help some poor soul. Situation: I want to do a lookup using a stored procedure for each value in a Row within a GridView. I use a lookup function in my code behind, evaluating the necessary bound fields. The problem is the SqlDataSource representing...
1
2536
by: Vili | last post by:
Hi all I would like to get some ideas and opinions of my solution for dataconnection on asp.net 2.0 I have created a class which encapsulates the sqldatasource usage. With my class one can set select-, insert-, update- and deletecommand with and without parameters and also get output parameters
0
1303
by: ADAC | last post by:
I am very familiar with Visual studio 2003 and trying to get a handle on 2005 I can set up the datasource and make it work fine when I databind it to a control like a gridview or details view. Everything is done automatically no programming. I need to take a sqldatasource that I have already created with parameters etc. Set the parameter in the code behind, run it against the database and get the result. in 2003 I would creat a command,...
1
3099
by: Pipo Dyer | last post by:
Hello Everybody, I am Using @@IDENTITY from MS Access (YES-It is possible) using SqlDataSource -NO STORE PROC- in ASP.NET {VB CODE} to retrieve the ID of a inserted record. Please keep in mind I am using a form page an code behing, and I have currently my ConnectionString within my form. Therefore http://www.mikesdotnetting.com/Article.aspx?ArticleID=54 was close but not exactly what I need at this point. So far I have done the following...
0
9554
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9989
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9927
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9812
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8814
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7360
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6640
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5268
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
3510
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.