如何使用文本框和按钮从Gridview搜索记录 [英] how to search a record from Gridview using textbox and button

查看:81
本文介绍了如何使用文本框和按钮从Gridview搜索记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从网格视图中搜索记录..
我想使用文本框和按钮查找记录

i want to search record from grid view ..
i want to use a textbox and a button to find a record

推荐答案

,您可以使用grid.Rows
遍历网格. 就像

foreach(grid.rows中的GridViewRow行)
{
控件cntrl = row.FindControls("controlName");

}

如果您有Label,则可以将其转换为Label并使用其中的属性.

将标签lblControlName = row.FindControl("controlName")作为标签;

如果您使用绑定列,则可以使用row.Cells []数组并找到值,上述情况将与Itemtemplate一起使用.

希望对您有所帮助.
you can iterate through the grid using grid.Rows
like

foreach(GridViewRow row in grid.Rows)
{
Control cntrl = row.FindControls("controlName");

}

if you have a Label then you can casta to Label and use the property from it.

Label lblControlName = row.FindControl("controlName") as Label;

the above case will work with Itemtemplate if you are using bound column you can use row.Cells[] array and find the value.

hope it helps..


//使用文本框和按钮从GridView中进行搜索
//在页面上输入一个文本框(txtSearch)和一个按钮(Search)
//遵循此代码.....
私有void SearchText()
{
/////////////在此处绑定网格
bindGrid();
字符串SrchExpression = null;
如果(!String.IsNullOrEmpty(txtSearch.Text))
{
SrchExpression = string.Format("{0}''%{1}%''",
GridName.SortExpression,txtSearch.Text);

}
dv.RowFilter ="CustomerName Like" + SearchExpression;
GridName.DataSource = dv;
GridName.DataBind();

}

//找到您的表情
公共字符串Highlight(字符串InputTxt)
{
字符串Search_Str = txtSearch.Text.ToString();
正则表达式RegExp =新正则表达式(Search_Str.Replace(","|").Trim(),
RegexOptions.IgnoreCase);
返回RegExp.Replace(InputTxt,
新的MatchEvaluator(Words));
}

公共字符串单词(匹配m)
{

返回< span class = highlight>" + m.Value +</span>";

}

受保护的无效btnSearch_Click(对象发送者,EventArgs e)
{
SearchText();
}
//To Search From GridView Using Textbox And Button
//Take a textbox(txtSearch) and A button(Search) on your Page
//Follow this Code .....
private void SearchText()
{
/////////////Bind Your Grid Here
bindGrid();
string SrchExpression = null;
if (!String.IsNullOrEmpty(txtSearch.Text))
{
SrchExpression = string.Format("{0} ''%{1}%''",
GridName.SortExpression, txtSearch.Text);

}
dv.RowFilter = "CustomerName Like" + SearchExpression;
GridName.DataSource = dv;
GridName.DataBind();

}

//To find Your Expression
public string Highlight(string InputTxt)
{
string Search_Str = txtSearch.Text.ToString();
Regex RegExp = new Regex(Search_Str.Replace(" ", "|").Trim(),
RegexOptions.IgnoreCase);
return RegExp.Replace(InputTxt,
new MatchEvaluator(Words));
}

public string Words(Match m)
{

return "<span class=highlight>" + m.Value + "</span>";

}

protected void btnSearch_Click(object sender, EventArgs e)
{
SearchText();
}


这篇关于如何使用文本框和按钮从Gridview搜索记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆