Most examples I found are passing text values and I need it to be an integer. I need to be able to use this value as a parameter for a gridview control associated with an SQL database. Please help... any insight would be appreciated.
Hi, look at using Session state to store your values. You can store many data types in session. All you need to do when reading back session variables is to cast the session value to the correct type. For example:
VB
Dim myInt as Integer = 5
'Save to session
session("myInt") = myInt
'Read it back
Dim readInt as Integer = CType(Session.Item("myInt"), Integer)
or in C#
int myInt = 5;
//Save to session
session("myInt") = myInt;
//Read it back
int readInt = Convert.ToInt32(Session.Item("myInt"));
A.Venkatesan
Microsoft Certified Professional
Please mark the replies as answers if they help or unmark if not.
If you have any feedback about my replies, please contact venkatmca008@gmail.com
By pass to another page, do you mean through QueryString? If so, know that QueryString values are always strings. You can convert them to int using int.Parse.
However, if you put a string in a Parameter of an SqlCommand (or use QueryStringParameter in the SelectParameters of an SqlDataSource) you won't even need to do that. Parameters are usually smart enough to make the Sql server do the hard work.
Superguppie.
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
When all you've got is a Hammer, Every Problem looks like a Nail. Michael Swain.
Marked as answer by cherieformacion on Feb 24, 2012 10:45 PM
superguppie - Ultimately I want to use the string in the QueryStringParameter in the Select Parameters of SqlDataSource. I tried doing this and it doesn't work, no results in my gridview. Below are the codes I used. Please advice... thanks!
CodeBehind on the first page where users select from a RadioButtonList:
="SELECT tblDescriptors.IDNO, tblDescriptors.Lastname, tblDescriptors.Firstname, tblDescriptors.SSNO, tblDescriptors.Birthdate, tblProgram.ProgramEntryDate, tblProgram.TerminationDate, CASE WHEN tblprogram.terminationdate IS NULL THEN 'Active' ELSE 'Inactive'
END AS Status, tblProgram.ProgramID FROM tblDescriptors INNER JOIN tblProgram ON tblDescriptors.IDNO = tblProgram.IDNO WHERE (tblProgram.ProgramID = @programid)">
cherieformac...
Member
5 Points
3 Posts
I want to pass an INTEGER (programid) from the first page to the next.
Feb 23, 2012 11:07 PM|LINK
Most examples I found are passing text values and I need it to be an integer. I need to be able to use this value as a parameter for a gridview control associated with an SQL database. Please help... any insight would be appreciated.
smcoxon
Contributor
5455 Points
948 Posts
Re: I want to pass an INTEGER (programid) from the first page to the next.
Feb 23, 2012 11:32 PM|LINK
Hi, look at using Session state to store your values. You can store many data types in session. All you need to do when reading back session variables is to cast the session value to the correct type. For example:
VB
Dim myInt as Integer = 5 'Save to session session("myInt") = myInt 'Read it back Dim readInt as Integer = CType(Session.Item("myInt"), Integer)or in C#
int myInt = 5; //Save to session session("myInt") = myInt; //Read it back int readInt = Convert.ToInt32(Session.Item("myInt"));Smcoxon
No Gem is ever polished without some friction.
venkatmca008
Participant
1810 Points
341 Posts
Re: I want to pass an INTEGER (programid) from the first page to the next.
Feb 24, 2012 12:28 AM|LINK
hi..please refer this
http://forums.asp.net/t/1223291.aspx
http://stackoverflow.com/questions/8241470/asp-net-pass-a-value-into-next-page
Microsoft Certified Professional
Please mark the replies as answers if they help or unmark if not.
If you have any feedback about my replies, please contact venkatmca008@gmail.com
superguppie
All-Star
48225 Points
8679 Posts
Re: I want to pass an INTEGER (programid) from the first page to the next.
Feb 24, 2012 01:39 PM|LINK
By pass to another page, do you mean through QueryString? If so, know that QueryString values are always strings. You can convert them to int using int.Parse.
However, if you put a string in a Parameter of an SqlCommand (or use QueryStringParameter in the SelectParameters of an SqlDataSource) you won't even need to do that. Parameters are usually smart enough to make the Sql server do the hard work.
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
When all you've got is a Hammer, Every Problem looks like a Nail. Michael Swain.
cherieformac...
Member
5 Points
3 Posts
Re: I want to pass an INTEGER (programid) from the first page to the next.
Feb 24, 2012 04:06 PM|LINK
Thanks for the responses :)
superguppie - Ultimately I want to use the string in the QueryStringParameter in the Select Parameters of SqlDataSource. I tried doing this and it doesn't work, no results in my gridview. Below are the codes I used. Please advice... thanks!
CodeBehind on the first page where users select from a RadioButtonList:
protected void NextButton_Click(object sender, EventArgs e)
{
Response.Redirect("ProgramPage.aspx?ProgramID="+ Server.UrlEncode(ProgramID.Text));
}
Select Statement on the second page:
SelectCommand
="SELECT tblDescriptors.IDNO, tblDescriptors.Lastname, tblDescriptors.Firstname, tblDescriptors.SSNO, tblDescriptors.Birthdate, tblProgram.ProgramEntryDate, tblProgram.TerminationDate, CASE WHEN tblprogram.terminationdate IS NULL THEN 'Active' ELSE 'Inactive' END AS Status, tblProgram.ProgramID FROM tblDescriptors INNER JOIN tblProgram ON tblDescriptors.IDNO = tblProgram.IDNO WHERE (tblProgram.ProgramID = @programid)">
<SelectParameters>
<asp:QueryStringParameter Name="programid" QueryStringField="ProgramID" Type="Object" />
</SelectParameters>
cherieformac...
Member
5 Points
3 Posts
Re: I want to pass an INTEGER (programid) from the first page to the next.
Feb 24, 2012 10:46 PM|LINK
I got it to work!! Yay!!
Tons of thanks to all who helped out. :)
Peace.....