开发者

View Database Columns via Checkbox WebFrom and Cookies

I am using the telerik MVC template and have a database that has a huge number of columns and the telerik grid does not have a horizontal scroll bar, 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. Before adding the cookies, the user only had to press apply once for only those columns to appear. However, if the user then tried to sort or filter one of these columns, it would revert back to showing all of the columns. So, I created a cookie to store the selected information. Unfortunately, this only helped with the selection of the first filter. If a second filter is used, it would, again, show all of the columns instead of just the ones selected. Furthermore, the user now has to press apply twice for their selections to show properly on the grid view. Here is a brief explanation of how I have everything coded:

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 (Request.Cookies["DBCols"]["csurr"] != null)
                     {
                         if (Request.Cookies["DBCols"].Values["csurr"].Equals("True")) { columns.Bound(o => o.csurr).Title("开发者_Python百科Cust. No."); }
                     }
                     if (Request.Cookies["DBCols"]["rhosurr"] != null)
                     {
                         if (Request.Cookies["DBCols"].Values["rhosurr"].Equals("True")) { columns.Bound(o => o.rhosurr).Title("RHO No."); }
                     }
                     if (Request.Cookies["DBCols"]["lockid"] != null)
                     {
                         if (Request.Cookies["DBCols"].Values["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? csurr, bool? rhosurr, bool? lockid /* And Several More */)
{
ViewData["csurr"] = csurr ?? true;
ViewData["rhosurr"] = rhosurr ?? true;
ViewData["lockid"] = lockid ?? true;

if ((bool)ViewData["csurr"]) { DBCols.Values["csurr"] = (ViewData["csurr"].ToString());
}
else { DBCols.Values["csurr"] = "False"; }
if ((bool)ViewData["rhosurr"]) { DBCols.Values["rhosurr"] = (ViewData["rhosurr"].ToString()); }
else { DBCols.Values["rhosurr"] = "False"; }
if ((bool)ViewData["lockid"]) { DBCols.Values["lockid"] = (ViewData["lockid"].ToString()); }
else { DBCols.Values["lockid"] = "False"; }
//And Several more

var db = new MillieOrderDB();
var listView = from m in db.vw_cadords
orderby m.createstamp descending
select 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. Anyone have any ideas why I am having to press apply twice, why I can not use more than one filter, and how to avoid this?


It turns out that the reason I had to hit apply twice and why when applying more than one filter caused issues was because I had everything in the Index ActionResult. Once I moved all the form data to its own ActionResult and then did RedirecttoAction("Index"), everything worked fine!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜