0

Imagine you have a menu with categories. Each of which contains a link to the parent page, but with a querystring. For instance:

<a href="?category=5">Category 5</a>

This shows some items for category 5 in a gridview. Now I want to have the ability to sort said gridview, also using a querystring. So the querystring I should end up with is:

?category=5&sortby=namedesc

But I wouldn't know what category was already chosen. So I'd have to take the existing querystring and add &sortby=namedesc. Now if I were to choose another category from the menu, the querystring should of course not add a new "&category=" but change the existing one accordingly.

The only way I've figured out how to do this is to make them into link buttons and in the "onclick" analyze the existing querystring, and append/change values as needed. Then doing

Request.Redirect("page.aspx" + newQueryString);

This should work, but it seems a highly inefficient way of doing this as it will require 2 postbacks for each click.

My question is: Is there a smarter/better way of handling this?

Daniel Olsen
  • 1,020
  • 2
  • 15
  • 27
  • You just need to format the link when rendering the page. It would be easier if you provide the markup of he GridView and the Menu – Jupaol Sep 25 '12 at 22:26
  • Thing is that I haven't made anything yet, but I came across the problem while thinking about the best way I could make my design. So I have nothing to give you just yet. How do you mean format? – Daniel Olsen Sep 25 '12 at 22:28
  • What are you using to display/sort your data? Have you considered jQuery datatables? http://datatables.net – Jason Towne Sep 25 '12 at 22:43
  • Now that's awesome Jason. Thank you for that fine link. Now the thing is that I'm not using anything yet, since I haven't made it yet. Its just a thought experiment, but I can think of many different instances where I might need to add to a querystring that doesn't involve a table/gridview. And with the jquery gridview, I wouldn't be able to provide a direct link to a sorted and filtered (by category) datatable right? :) – Daniel Olsen Sep 25 '12 at 22:52
  • Another example: I have the categories and then have a search box. So as I have a category (?category=5) and I type something into the search field it will create the querystring "?category=5&searchstring=testing". – Daniel Olsen Sep 25 '12 at 22:57

0 Answers0