Tags

, , ,

HI,

Querystring (also called an HTTP Querystring) is part of the set of characters automatically input in the address bar of a dynamic Web site when a user makes a request for information according to certain criteria.

I’ll be discussing now ways to pass values as Parameters in Querystring:

1> In my last post I passed only one parameter in my query string as:

/localhost/?PN=test

I fetched the same using:

String PN = Request.QueryString[“PN”].ToString();

 

2> But, In case we have known Multiple values that are being passed in a sequence, we can use multiple parameters in Querystring :

/localhost/?PN=test&FN=Ashwani&LN=Kumar&CT=Delhi&CTR=India

The same can be fetched as:

String PN = Request.QueryString[“PN”].ToString();
String FN = Request.QueryString[“FN”].ToString();
String LN = Request.QueryString[“LN”].ToString();
String CT = Request.QueryString[“CT”].ToString();
String CTR = Request.QueryString[“CTR”].ToString();

 

3> And what if we have multiple values and donno the count??

For that we can use the same parameter with values as comma seperated:

/localhost/?PN=123,234,345,456,567

The same can now be fetched as:

String[] strSample = Request.QueryString[“pid”].Split(‘,’);
int l = strSample.Length;

for (int i = 0; i <= strSample.Length; i++)
{
String PN = strSample[i];
// use the variable in your code accordingly
}
Hope that was helpful.
Thanks !!!

😀