This question is locked. New answers and comments are not allowed.
I have a database that has a huge number of columns so I created checkboxes for the user to select exactly what columns they want to view. It works well enough in that when I first go to the page it shows the checkboxes at top with the Apply button and the grid view underneath. Because nothing has been submitted from the WebForm, the grid view shows all the columns. Once the user hits apply it shows the columns they have selected. However, if the user then tries to sort or filter one of these columns, it reverts back to showing all of the columns. Here is a brief explanation of how I have everything coded:
Index View
Controller
I am working just in the Index ActionResult for now to keep things in one place while I figure out how to get this all to work. I've also tried making my if (ViewData["osurr"].Equals(true)) { columns.Bound(o => o.osurr).Title("Ad No."); } statement have an else { columns.Bound(o => o.osurr).Hidden(true); } without success. . . . I've also tried testing that the ViewData is not null ex: if (ViewData["osurr"] != null) { if (ViewData["osurr"].Equals(true)) { columns.Bound(o => o.osurr).Title("Ad No."); } } and this didn't help either.
It seems that the ViewData is refreshed along with the view any time any Action is called. Does anyone have any ideas on how to get this to work?
Index View
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"><% using (Html.BeginForm("Index", "Order")) { %> <p> <%= Html.CheckBox("osurr", true, "Ad Number")%>Ad Number //I set this and a few other columns to default to true <%= Html.CheckBox("csurr", false, "Customer Number")%>Customer Number <%= Html.CheckBox("rhosurr", false, "RHO Number")%>RHO Number <%= Html.CheckBox("lockid", false, "Lock ID")%>Lock ID //And several more </p> <input type="submit" value="Apply" /><% } %><% Html.Telerik().Grid(Model) .Name("Grid") .Columns(columns => { columns.Template(o => {%> <%=Html.ActionLink("Detail", "Edit", new { id = o.osurr })%> <% }).Width(25); if (ViewData["osurr"].Equals(true)) { columns.Bound(o => o.osurr).Title("Ad No."); } if (ViewData["csurr"].Equals(true)) { columns.Bound(o => o.csurr).Title("Cust. No."); } if (ViewData["rhosurr"].Equals(true)) { columns.Bound(o => o.rhosurr).Title("RHO No."); } if (ViewData["lockid"].Equals(true)) { columns.Bound(o => o.lockid).Title("Lock ID"); } //And again, several more. }) .Groupable(grouping => grouping.Enabled(true)) .Resizable(resizing => resizing.Columns(true)) .Filterable(filter => filter.Enabled(true)) .Sortable(sorting => sorting.Enabled(true)) .Pageable(paging => paging.Enabled(true).PageSize(25)) .Render(); %></asp:Content>Controller
public ActionResult Index(bool? osurr, bool? csurr, bool? rhosurr, bool? lockid /* And Several More */)
{ViewData["osurr"] = osurr ?? true;ViewData["csurr"] = csurr ?? true;ViewData["rhosurr"] = rhosurr ?? true;ViewData["lockid"] = lockid ?? true;//And Several more var db = new MillieOrderDB();var listView = from m in db.vw_cadordsorderby m.createstamp descendingselect m;return View(listView);
}I am working just in the Index ActionResult for now to keep things in one place while I figure out how to get this all to work. I've also tried making my if (ViewData["osurr"].Equals(true)) { columns.Bound(o => o.osurr).Title("Ad No."); } statement have an else { columns.Bound(o => o.osurr).Hidden(true); } without success. . . . I've also tried testing that the ViewData is not null ex: if (ViewData["osurr"] != null) { if (ViewData["osurr"].Equals(true)) { columns.Bound(o => o.osurr).Title("Ad No."); } } and this didn't help either.
It seems that the ViewData is refreshed along with the view any time any Action is called. Does anyone have any ideas on how to get this to work?