How do I highlight a row in a datagrid?

  • Thread starter Thread starter mike
  • Start date Start date
M

mike

I'm trying to highlight a specific row in a datagrid who's contition matches
..text = "Dawn"

i've been playing with the code below without much luck, is there a foreach
loop i could do, like
(
foreach(datarows in datagrid)
check if the first cell in the row contains Dawn
if so highlight the row.
)

=== Code i've been playing with ===
for(int x=0;x<=dgQnARooms.Items.Count -1;x++)
{
if(dgQnARooms.Items[x].Cells[0].Text == "Dawn")
{
dgQnARooms.ItemStyle.BackColor = System.Drawing.Color.Cornsilk;
}
}
 
This article might of help..
http://www.codeproject.com/csharp/custom_datagridcolumnstyl.asp

HTH




mike said:
I'm trying to highlight a specific row in a datagrid who's contition matches
.text = "Dawn"

i've been playing with the code below without much luck, is there a foreach
loop i could do, like
(
foreach(datarows in datagrid)
check if the first cell in the row contains Dawn
if so highlight the row.
)

=== Code i've been playing with ===
for(int x=0;x<=dgQnARooms.Items.Count -1;x++)
{
if(dgQnARooms.Items[x].Cells[0].Text == "Dawn")
{
dgQnARooms.ItemStyle.BackColor = System.Drawing.Color.Cornsilk;
}
}
 
Does this work the same way for ASP.net datagrid?

Thanks
Mike


Kayess said:
This article might of help..
http://www.codeproject.com/csharp/custom_datagridcolumnstyl.asp

HTH




mike said:
I'm trying to highlight a specific row in a datagrid who's contition matches
.text = "Dawn"

i've been playing with the code below without much luck, is there a foreach
loop i could do, like
(
foreach(datarows in datagrid)
check if the first cell in the row contains Dawn
if so highlight the row.
)

=== Code i've been playing with ===
for(int x=0;x<=dgQnARooms.Items.Count -1;x++)
{
if(dgQnARooms.Items[x].Cells[0].Text == "Dawn")
{
dgQnARooms.ItemStyle.BackColor = System.Drawing.Color.Cornsilk;
}
}
 
No it is different, there is another article you may
find useful:
http://www.csharphelp.com/archives3/archive543.html
about 3/4 down the page there is a section on highlighting.

HTH
Steve


mike said:
Does this work the same way for ASP.net datagrid?

Thanks
Mike


Kayess said:
This article might of help..
http://www.codeproject.com/csharp/custom_datagridcolumnstyl.asp

HTH




mike said:
I'm trying to highlight a specific row in a datagrid who's contition matches
.text = "Dawn"

i've been playing with the code below without much luck, is there a foreach
loop i could do, like
(
foreach(datarows in datagrid)
check if the first cell in the row contains Dawn
if so highlight the row.
)

=== Code i've been playing with ===
for(int x=0;x<=dgQnARooms.Items.Count -1;x++)
{
if(dgQnARooms.Items[x].Cells[0].Text == "Dawn")
{
dgQnARooms.ItemStyle.BackColor = System.Drawing.Color.Cornsilk;
}
}
 
Hi,

You can do that using the ItemDataBound event of the grid, and change the
CSS of that row.

You can also use Page.PreRender event and iterate in the rows and also set
the correct CSS for that row.

I have some code if you need it.


Cheers,
 
Back
Top