Often I’ve had to build a page that didn’t allow the datagrid or listview built in sort options so I came up with this function so that you can keep filters and change the sorting and direction of the page.
public string sPageURLwVariables(string sArrow, string sDir) { string sOriginalURL = HttpContext.Current.Request.Url.PathAndQuery; string sCleanURL = ""; string[] sURLVariables = sOriginalURL.Split(new char[] { '?', '&' }); if (sURLVariables.GetLength(0) > 0) { foreach (string sURLVariable in sURLVariables) { if (sURLVariable != HttpContext.Current.Request.Url.AbsolutePath) { if (sURLVariable.IndexOf(sArrow, 0) < 1) { if (sCleanURL != "") { sCleanURL += "&"; } sCleanURL += sURLVariable; Response.Write(sURLVariable + "<br>"); } } } if (sCleanURL != "") { sCleanURL = HttpContext.Current.Request.Url.AbsolutePath + "?" + sCleanURL; } else { sCleanURL = HttpContext.Current.Request.Url.AbsolutePath; } return sCleanURL; } else { return HttpContext.Current.Request.Url.AbsolutePath; } }
Last Updated on October 26, 2015