How do I highlight a row in a datagrid?

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;
}
}
 
K

Kayess

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;
}
}
 
M

mike

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;
}
}
 
K

Kayess

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;
}
}
 
I

Ignacio Machin \( .NET/ C# MVP \)

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,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top