Click here to Skip to main content
15,897,187 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
the query string is
HTML
<a href="http://beta.firago.com/contact_us.aspx?item_name_1=Aito&item_quantity_1=11&item_price_1=875&item_options_1=pageLink%3A+aito.html%2C+bedrooms%3A+2+x+1+Bedroom&item_name_2=Peto&item_quantity_2=1&item_price_2=875&item_options_2=pageLink%3A+aito.html%2C+bedrooms%3A+2+x+1+Bedroom&return=success.html&cancel_return=cancel.html#.T-EgUMV5dXY">


The values above relate to different products and there is the possiblity that there could be many products making it an even longer query string.

Specifically I would like to retrieve the values item_name_1 and item_name_2 and 3,4,5 etc if these are present.

I know i can use request.querystring("item_name_1") to get the value Aito above.

However I'm guessing I need perhaps a for loop to extract the values of all
ie something along the lines of
C#
(for i = 0; i < request.querystring.count; i++)
{
txtboxbody.text = request.querystring("item_name_" + i);
}


The above does not seem to work however. Any guidance would be appreciated.

Thanks
Posted
Comments
Bernhard Hiller 20-Jun-12 2:08am    
some design hints: a web browser might have some maximum length for the URL, so better change from GET to POST.
And next, try to implement things differently, by storing the shopping cart on the server and identifying it by a cookie or an id in the query string (also think of security concerns when doing so).

The following should help you in figuring out what you want to do:

C#
var str = @"http://beta.firago.com/contact_us.aspx?item_name_1=Aito&item_quantity_1=11&item_price_1=875&item_options_1=pageLink%3A+aito.html%2C+bedrooms%3A+2+x+1+Bedroom&item_name_2=Peto&item_quantity_2=1&item_price_2=875&item_options_2=pageLink%3A+aito.html%2C+bedrooms%3A+2+x+1+Bedroom&return=success.html&cancel_return=cancel.html#.T-EgUMV5dXY";
var re = new Regex(@"item_name_\d[^&]*=([^&]*)&");
var matches = re.Matches(str);
foreach (var m in matches)
    Console.WriteLine(m);

var match = re.Match(str);
int matchCount = 0;
while (match.Success)
{
    Console.WriteLine("Match" + (++matchCount));
    for (int i = 1; i <= 2; i++)
    {
        Group g = match.Groups[i];
        Console.WriteLine("Group" + i + "='" + g + "'");
        CaptureCollection cc = g.Captures;
        for (int j = 0; j < cc.Count; j++)
        {
            Capture c = cc[j];
            System.Console.WriteLine("Capture" + j + "='" + c + "', Position=" + c.Index);
        }
    }
    match = match.NextMatch();
}
Console.ReadLine();


Much of code is taken from http://msdn.microsoft.com/en-us/library/twcw2f1c.aspx[^]
 
Share this answer
 
I think you can handle it through array string and split it through &

then use for loop..I dont know if I am wrong..tell me if so..



Thanks
Ashish
 
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