Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have an ASP.NET website in which I have to perform a certain operation. I have to displaying the ID's from the DB on menu.aspx page in this format {1:2:3:4}. The above format is not a problem and can be just be written with

Response.Write("{");
for.. loop(until last ID)
{
Response.Write(query to fetch ID's) + ":";
}
Response.Write("}");


But here comes my question. I have to generate this ID when the user types the query within the URL somewhat like http://localhost/website/menu.aspx?search=yes

Note that I am saying that the user will type this URL. I know that query string can pass the values from one form to another but this is a single web form and if I attach this ?search=yes, it should return the result. How can this be done?
Something similar to searching in Google. For eg: I can type www.google.com/search?CP and I get the results

Edit
--
I am using this small code snippet for the query string

if (Request.QueryString["search"] != null) {

    Response.Write("{");
    for.. loop(until last ID) {
        Response.Write(query to fetch ID's) + ":";
    }
    Response.Write("}");
}


I have to change some things so that on this query string localhost/website/?search=codeproject , the codeproject should be appended to my output i.e codeproject{1:2:3:4). Similarly for all other values searched through query string should be appended to the output. How to do this?
Posted
Updated 18-Jan-11 6:02am
v4

You can get the value of your query string using

Request.QueryString["search"]
 
Share this answer
 
Comments
optimus_prime1 18-Jan-11 10:27am    
Hi, your answer was helpful. I have editted my question for another query in continuation this.
Thanks!
optimus_prime1 18-Jan-11 11:59am    
umm.. I am using this small code snippet for the query string http://pastebin.com/U7aGKcj9

I have to change some things so that on this query string localhost/website/?search=jessegavin , the jessegvain should be appended to my output i.e jessegavin{1:2:3:4). Similarly for all other values searched through query string should be appended to the output. Can you please help me in this too?
Hi
You can assign the query string value to a string variable and append the id's and out put the string variable using Response.Write

if (Request.QueryString["search"] != null)
{
string outputText = Request.QueryString["search"].ToString() + "{";
for.. loop(until last ID) {
outputText += (query to fetch ID's) + ":";
}
outputText += "}";
Response.Write(outputText);
}

NB: You can use String class available method for appending the strings for better performance

Hope this helps
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900