开发者

Generating output on query string

开发者 https://www.devze.com 2023-02-04 23:23 出处:网络
I have an ASP.NET website in which I have to perform a certain operation. I haveto 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 ca

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 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 开发者_Go百科?search=yes, it should return the result. How can this be done?

This is somewhat similar to searching in Google. For eg: I can type www.google.com/search?Stack and I get the results


The following example will work if there is a querystring parameter named "search" with any value (including blank).

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

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


Use the Request.QueryString collection:

foreach(var item in Request.QueryString)
{
       Response.Write(Request.QueryString[item] + ":");
}

//etc.
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号