How to highlight a gridrow based on value filter from the dataset. I want to show all data rows but highlight only the filtered rows
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Manoj Kumar Mandal198 reputationPosted Apr 30, 2015, 3:02 AM EDT
You can use OnRowDataBound event of grid to do so.
Here is a sample code for you
in aspx add
onrowdatabound="GridView1_RowDataBound"
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string i = e.Row.Cells[1].Text.ToString();
if(i.Equals("2"))
e.Row.BackColor = System.Drawing.Color.Red;
}
}
In this code i'm expecting that he value what you are matching exist on cell 1(cell count starts from 0 in grid) and checking if value is 2 change the color of row or else nothing.
---------------------------------------------------------------------------------------
If you find this answer helpful and solves your problem. Mark answered
Thank You
ashok kumar30 reputationPosted Apr 30, 2015, 3:37 AM EDT
I selected the Dropdown Nam, enter the txtbox ashok and click the button highlight the name in grid row using for dataset
Thanks in Advice
Vincent Maverick DuranoRank #238 · 10.3K reputationPosted Apr 30, 2015, 4:54 AM EDT
This should help you : Search records in GridView and highlight results in ASP.Net using C# and VB.Net
You can see the actual demo here: http://www.aspsnippets.com/Demos/922/
Manoj Kumar Mandal198 reputationPosted Apr 30, 2015, 9:38 PM EDT
I prefer go for javascript in this case.
Try this code
for textbox Code
grv1 is the name of your gridviev.
For complete code download attached file.