搜索不在Gridview上工作
我已在gridview上为此链接中的列实现了搜索。 我按照我的要求实施。但它不适合我。 请参阅代码供您参考: –
另请参阅JS脚本
$(function () { $('.form-control').each(function (i) { $(this).quicksearch("[id*=grdCSRPageData] tr:not(:has(th))", { 'testQuery': function (query, txt, row) { return $(row).children(":eq(" + i + ")").text().toLowerCase().indexOf(query[0].toLowerCase()) != -1; } }); }); });
另请参阅您的参考背后的代码: –
protected void grdCSRPageData_DataBound(object sender, EventArgs e) { GridViewRow row = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Normal); for (int i = 0; i < grdCSRPageData.Columns.Count; i++) { TableHeaderCell cell = new TableHeaderCell(); TextBox txtSearch = new TextBox(); txtSearch.Attributes["placeholder"] = grdCSRPageData.Columns[i].HeaderText; txtSearch.CssClass = "form-control"; cell.Controls.Add(txtSearch); row.Controls.Add(cell); } grdCSRPageData.HeaderRow.Parent.Controls.AddAt(1, row); }
网格的变化
protected void grdUser_DataBound(object sender, EventArgs e) { GridViewRow row = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Normal); for (int i = 0; i < grdUser.Columns.Count; i++) { TableHeaderCell cell = new TableHeaderCell(); TextBox txtSearch = new TextBox(); txtSearch.Attributes["placeholder"] = grdUser.Columns[i].HeaderText; txtSearch.CssClass = "form-control HaydaBre"; if (grdUser.Columns[i].HeaderText != "Action" && grdUser.Columns[i].HeaderText != "" && grdUser.Columns[1].HeaderText != "Select") // && grdUser.Columns[i].HeaderText != "" && grdUser.Columns[i].HeaderText != null && grdUser.Columns[i].HeaderText != "Select") { cell.Controls.Add(txtSearch); } row.Controls.Add(cell); } grdUser.HeaderRow.Parent.Controls.AddAt(1, row); }
当我添加HeaderText
!= Select
。 它停止为第一列工作,但它适用于另一列
表单控件类有很多元素。 那么你可以改变你的C#代码:
protected void grdCSRPageData_DataBound(object sender, EventArgs e) { GridViewRow row = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Normal); for (int i = 0; i < grdCSRPageData.Columns.Count; i++) { TableHeaderCell cell = new TableHeaderCell(); TextBox txtSearch = new TextBox(); txtSearch.Attributes["placeholder"] = grdCSRPageData.Columns[i].HeaderText; txtSearch.CssClass = "form-control HaydaBre"; cell.Controls.Add(txtSearch); row.Controls.Add(cell); } grdCSRPageData.HeaderRow.Parent.Controls.AddAt(1, row); }
和你的JS代码是: