Reputation: 4740
How can I put all data that are in a line in my GridView, in Bold style, if another column of this GridView has the value "1" for example ?
This columns, can't be visible to the user. I use SqlDataSource to fill my GridVIew
Upvotes: 0
Views: 1608
Reputation: 579
void myGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (((myobject)e.Row.DataItem).myfield == "1")
{
e.Row.CssClass="myclass";
}
}
}
Upvotes: 0
Reputation: 2700
You could:
Use the GridView.RowDataBound event to inspect the data you're writing to each column (you'd check for the value "1", in your case).
If your condition is met, set a flag.
Once the flag has been set, you can check it on writing each new row
(again, using the event detailed above). When writing the row you
want to appear as bold, check the flag. If the flag is set, change the CssClass
property of the Row object to a class you have created in your stylesheet, which has
text-weight:bold
or similar.
Upvotes: 1
Reputation: 28316
You can set font and other style information on each cell, which you can fetch with table.Rows[row].Cells[col]
where row/col are your row and column numbers.
Here's the documentation for TableCell
:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.tablecell.aspx
You should also be able to set the styles per-row by using the GridViewRow
class exposed by table.Rows
. Here's the link ot the MSDN article for it:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridviewrow.aspx
Upvotes: 0