我已经问了很多次..我得到了答案,但我不知道怎么做... 我有一个用于在gridview表中搜索文本的文本框..但我不知道该怎么做..请帮助我 sql database 2008,asp.net,c#
答案 0 :(得分:0)
您可以使用Dataview Rowfilter重新填充Gridview进行搜索..
.....
.....
DataView dvData = new DataView(yourDataTableGoesHere);
dvData .RowFilter = "Name LIKE 'j*'"
DGV.DataSource = dvData;
DGV.DataBind();
使用Jquery在搜索时突出显示数据网格视图
string SearchString = "";
protected void Page_Load(object sender, EventArgs e)
{
txtSearch.Attributes.Add("onkeyup", "setTimeout('__doPostBack(\'" + txtSearch.ClientID.Replace("_", "$") + "\',\'\')', 0);");
if (!IsPostBack)
{
Gridview1.DataBind();
}
}
protected void txtSearch_TextChanged(object sender, EventArgs e)
{
SearchString = txtSearch.Text;
}
public string HighlightText(string InputTxt)
{
string Search_Str = txtSearch.Text.ToString();
// Setup the regular expression and add the Or operator.
Regex RegExp = new Regex(Search_Str.Replace(" ", "|").Trim(), RegexOptions.IgnoreCase);
// Highlight keywords by calling the
//delegate each time a keyword is found.
return RegExp.Replace(InputTxt, new MatchEvaluator(ReplaceKeyWords));
// Set the RegExp to null.
RegExp = null;
}
public string ReplaceKeyWords(Match m)
{
return "<span class=highlight>" + m.Value + "</span>";
}