n ASP .NET 4.5 SelectMethod is not able to bind data to grid view on button click
我正在使用ASP.Net 4.5,并且面临与使用"选择方法"进行网格视图的数据绑定有关的问题。
网格也可以将数据绑定到自定义分页上。
问题在于过滤数据。我有一个asp按钮,通过单击此按钮,我可以使用存储的proc获取经过过滤的数据。但是这次网格无法在SelectMethod中调用我在aspx页面中针对该网格提到的方法。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | <asp:GridView ID="gEmployee" runat="server" AutoGenerateColumns="False" OnRowCommand="gEmployee_Command" CellPadding="4" OnRowDataBound="gEmployee_RowDataBound" AllowCustomPaging="true" PageSize="10" PagerSettings-Visible="false" CssClass="mGrid" AllowSorting ="true" AlternatingRowStyle-CssClass="alt" ItemType="ModelEntityLayer.ClsEmployee" SelectMethod="BindGrid" OnSorting ="gEmployee_OnSorting" HeaderStyle-Wrap="false" DataKeyNames="PropClockNumber"> |
上面的
代码显示了我为网格视图设置的属性。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | public IQueryable<ClsEmployee> BindGrid() { int intTotalPages = 0; objBALEmployee = new ClsEmployeeBAL(); List<ClsEmployee> employee = null; if ((string)Session["QueryResult"] != null) { employee = objBALEmployee.GetPageWiseData(gEmployee.PageIndex, gEmployee.PageSize, ViewState["SortExpression"] != null ? ViewState["SortExpression"].ToString() : ViewState["ClockNumber"].ToString(), ViewState["SortOrder"] != null ? ViewState["SortOrder"].ToString() :"asc", ref intTotalPages, ((string)Session["QueryResult"])); Session.Remove("QueryResult"); } else { if (Convert.ToInt32(ViewState["IsEditSearch"]) != 1) { employee = objBALEmployee.GetPageWiseData(gEmployee.PageIndex, ViewState["SortExpression"] != null ? ViewState["SortExpression"].ToString() : ViewState["ClockNumber"].ToString(), ViewState["SortOrder"] != null ? ViewState["SortOrder"].ToString() :"asc", gEmployee.PageSize, ref intTotalPages); } else { employee = objBALEmployee.GetPageWiseData(gEmployee.PageIndex, gEmployee.PageSize, ViewState["SortExpression"] != null ? ViewState["SortExpression"].ToString() : ViewState["ClockNumber"].ToString(), ViewState["SortOrder"] != null ? ViewState["SortOrder"].ToString() :"asc", ref intTotalPages, dlEmployee.SelectedValue+" = '"+txtSearch.Text.Trim()+"'"); } } var lstEmployee = employee.AsQueryable(); if (intTotalPages > 0) { CustomPager.TotalPages = intTotalPages %gEmployee.PageSize == 0 ? intTotalPages /gEmployee.PageSize : intTotalPages / gEmployee.PageSize + 1; CustomPager.Visible = true; lblNoRecordsFound.Visible = false; NoRecords.Visible = false; } else { CustomPager.Visible = false; lblNoRecordsFound.Visible = true; NoRecords.Visible = true; } ExportData1.DisableBtn(gEmployee); ExportData.ExportCheck = false; return lstEmployee; } |
上面的代码显示了我为grid中的selectMethod设置的
受保护的无效btnGo_Click(对象发送者,EventArgs e)
1 2 3 4 5 6 7 8 9 10 11 | { ViewState["IsEditSearch"] ="1"; hiddenSearchField.Value = dlEmployee.SelectedValue; hiddenSearchValue.Value = txtSearch.Text.Trim(); gEmployee.SelectMethod ="BindGrid"; } |
上面的代码是为单击按钮而编写的。
尽管我在点击代码上再次编写了
请对此进行指导。
谢谢。
我认为您需要在
1 2 3 4 5 6 7 8 9 | protected void btnGo_Click(object sender, EventArgs e) { ViewState["IsEditSearch"] ="1"; hiddenSearchField.Value = dlEmployee.SelectedValue; hiddenSearchValue.Value = txtSearch.Text.Trim(); gEmployee.SelectMethod ="BindGrid"; gEmployee.DataBind(); } |