3

This is a simple question but I was wondering how to do this. I have a gridview that has a list of customers and in the gridview there is a linkbutton as a template field that says view cart. In the onclick method I have

Response.Redirect("~/Cart.aspx?ID=" + Request.QueryString["ID"]);

On the cart aspx page I have another gridview that I want it to display just the items in that customers specific cart. This gridview has a querystring parameter

            <SelectParameters>
            <asp:QueryStringParameter Name="ID" QueryStringField="ID" Type="String" />
        </SelectParameters>

However rightnow, nothing is showing up in the gridview for the cart. How can I achieve my goal?

Jamie
  • 107
  • 2
  • 11
  • why don't you do `Response.Redirect(string.Format("~Cart.Asppx?ID={0}, Request.QueryString["ID"].ToString()));` – MethodMan Jun 28 '16 at 14:34
  • 1
    @MethodMan `Request.QueryString["ID"]` already returns string no need of `.ToString()` correct me If I wrong – Jaydip Jadhav Jun 28 '16 at 14:36
  • if it's an Object it has to be cast to specific type either way the OP can try it using the `string.Format` command – MethodMan Jun 28 '16 at 14:37
  • 1
    `string.Format` does a `ToString()` on whatever you pass to it, so you are right, no need. – Crowcoder Jun 28 '16 at 14:41
  • Your problem lies somewhere else. Maybe the select query returns no data. BTW, [see how to properly redirect](https://blogs.msdn.microsoft.com/tmarq/2009/06/25/correct-use-of-system-web-httpresponse-redirect/) – Crowcoder Jun 28 '16 at 14:42
  • @jamie does you grid have the values for the `CartId`. Should be pretty simple if you populate your grid with `CartId` values. You can handle the rowcommand event in code behind and extract the `CartId`, build your querystring and redirect accordingly – JustLearning Jun 28 '16 at 14:50
  • @JustLearning my Grid does have values for CartID however I do not want the cart ID to be displayed on the gridview – Jamie Jun 28 '16 at 15:06
  • @Jamie you dont have to display it, set the CSS for the header and item to display:none. So create a style `display:none;` i usually call it `hidden-field` then set the two properties: `Item-CSS='hidden-field'` and the same for `Header-CSS` – JustLearning Jun 28 '16 at 19:30

1 Answers1

0
 var routeValuesDictionary = new RouteValueDictionary();
foreach (var key in Request.QueryString.AllKeys)
{
    routeValuesDictionary.Add(key, Request.QueryString[key]);
}
return RedirectToAction("ActionName", "Controller", new RouteValueDictionary(routeValuesDictionary));