本文介绍了使用dataview搜索gridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我有一个gridview,它包含不同数据类型的列。 我提供了类型和搜索功能... 每当用户输入他的标准值时列被检查并且适当的行被过滤.. 它对varchar工作正常...但是int,float有一些问题... 我正在使用dv。 RowFilter .... I have a gridview which consists of columns with different datatypes..I have provided type and search functionality...Whenever user types his criteria values of all columns are checked and appropriate rows are filtered..It works fine with varchar... But has some problems with int,float...I am using dv.RowFilter....criteria = ViewState["Criteria"].ToString(); string selected = dropdownCriteria.SelectedValue; string textEntered = searchBox.Value.ToString(); DataSet ds = new DataSet(); ds = (DataSet)ViewState["InitialData"]; DataView dv = new DataView(); dv = ds.Tables[0].DefaultView; dv.RowFilter = selected + " like '" + textEntered + "%'"; reportGrid.DataSource = dv; reportGrid.DataBind(); reportGrid.AllowPaging = false; reportGrid.AllowSorting = false; reportGrid.AutoGenerateDeleteButton = false; reportGrid.AutoGenerateEditButton = false; panelGrid.Update(); DataTable dt = new DataTable(); dt = dv.ToTable(); DataSet tempDS = new DataSet(); tempDS.Tables.Add(dt); reportGrid.AllowPaging = true; reportGrid.AllowSorting = true; reportGrid.AutoGenerateDeleteButton = true; reportGrid.AutoGenerateEditButton = true; ViewState["CurrData"] = tempDS; 推荐答案 criteria = ViewState["Criteria"].ToString();string selected = dropdownCriteria.SelectedValue;string textEntered = searchBox.Value.ToString();DataSet ds = new DataSet();ds = (DataSet)ViewState["InitialData"];reportGrid.DataSource = ds.Tables[0].AsEnumerable().Where(s=>s[selected].ToString().StartsWith(textEntered)).OrderBy(s=>s[selected].ToString()).CopyToDataTable();reportGrid.DataBind();reportGrid.AllowPaging = false;reportGrid.AllowSorting = false;reportGrid.AutoGenerateDeleteButton = false;reportGrid.AutoGenerateEditButton = false;panelGrid.Update();DataTable dt = new DataTable();dt = ds.Tables[0].AsEnumerable().Where(s=>s[selected].ToString().StartsWith(textEntered)).OrderBy(s=>s[selected].ToString()).CopyToDataTable();DataSet tempDS = new DataSet();tempDS.Tables.Add(dt);reportGrid.AllowPaging = true;reportGrid.AllowSorting = true;reportGrid.AutoGenerateDeleteButton = true;reportGrid.AutoGenerateEditButton = true;ViewState["CurrData"] = tempDS; --Amit --Amit public string EscapeLikeValue(string valueWithoutWildcards) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); for (int i = 0; i < valueWithoutWildcards.Length; i++) { char c = valueWithoutWildcards[i]; if (c == '*' || c == '%' || c == '[' || c == ']') sb.Append("[").Append(c).Append("]"); else if (c == '\'') sb.Append("''"); else sb.Append(c); } return sb.ToString(); } 这篇关于使用dataview搜索gridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-18 22:48