Dynamic Rows and Colors

R

Randy Rubin

What I am trying to do is Change the color of a row from a value that is in
a Database using the ItemStyle-BackColor Property. The value in the DB is
the color name. I keep getting a number of errors:

BC30676: 'DataBinding' is not an event of
'System.Web.UI.WebControls.BoundColumn'

Or
Literal content ('<asp:BoundColumn DataField="UID" HeaderText="UID"
ItemStyle-Font-Size="8" ReadOnly="true"
ItemStyle-BackColor=system.drawing.color.fromname(BomView.FieldValue("EngAdd
", Container)) Visible="False"/>') is not allowed within a
'System.Web.UI.WebControls.DataGridColumnCollection'.


So is there an easy way to do this?

Randy
 
G

Gai

Try adding the "ItemDataBound" Datagrid event and do the following:

private void DataGrid1_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
string strColorName = e.Item.Cells[IndexOfColorField].Text;
e.Item.BackColor = System.Drawing.Color.FromName(strColorName);
}
}

Hope it helps, Gai.
 
G

Gai

Try adding the "ItemDataBound" Datagrid event and do the following:

private void DataGrid1_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
string strColorName = e.Item.Cells[IndexOfColorField].Text;
e.Item.BackColor = System.Drawing.Color.FromName(strColorName);
}
}

Hope it helps, Gai.
 

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

Members online

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,832
Latest member
GlennSmall

Latest Threads

Top