Click here to Skip to main content
15,916,692 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i want to search record from grid view ..
i want to use a textbox and a button to find a record
Posted

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..
 
Share this answer
 
//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();
}
 
Share this answer
 
Comments
rkthiyagarajan 16-Sep-11 10:17am    
Use Pre Tag...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900