3
Answers

gridview select row change color

We have 100 records in gridview and we want to select 90th record. But user is not interested to scroll through mouse and see that record.

I have one textbox and button if i enter the    column value the particular row will be scroll and highlighted this is my Source code

protected void Button1_Click(object sender, EventArgs e)
{

String searchTerm = TextBox3.Text;
//if the column index is 1 the we search by code and 2 if we search by name
int columnIndex = 1;
bool found = false;
for (int i = 0; i < GridView1.Rows.Count; i++)
{
//change background color to yellow for the rows that contain the searched value
if (GridView1.Rows[i].Cells[columnIndex].Text.ToString().StartsWith(searchTerm))
{
if (searchTerm != "")
{
GridView1.Rows[i].BackColor = Color.SkyBlue;

}
else
{
GridView1.Visible = true;
GridView1.Rows[0].BackColor = Color.SkyBlue;
}
}


Thank you,

Answers (3)