Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then e.Item.Attributes.Add("onmouseover", "this.style.backgroundColor='Silver'") e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='white'") End If End Sub
private void AddCustomDataTableStyle() { DataGridTableStyle ts1 = new DataGridTableStyle(); ts1.MappingName = "Customers"; // Set other properties. ts1.AlternatingBackColor = Color.LightGray; /* Add a GridColumnStyle and set its MappingName to the name of a DataColumn in the DataTable. Set the HeaderText and Width properties. */
if(e.Item.ItemType == ListItemType.Item)//普通项
{
System.Drawing.Color tmp1 = e.Item.BackColor;}
if(e.Item.ItemType == ListItemType.AlternatingItem)//交替项
{
System.Drawing.Color tmp2 = e.Item.BackColor;}
--------------------------------------------------------------------------------------
<tr onmouseout="this.style.backgroundColor='Color [Empty]'" onmouseover="this.style.backgroundColor='#C0C0FF'" style="color:#4A3C8C;background-color:#E7E7FF;">
--------------------------------------------------------------------------------------
但我想要的是style="color:#4A3C8C;background-color:#E7E7FF;"中的background-color:#E7E7FF,有办法取出来吗?
DV=null;
//絪胯篈┪獶絪胯篈
if(e.Item.ItemType==ListItemType.Item||e.Item.ItemType==ListItemType.AlternatingItem||e.Item.ItemType==ListItemType.EditItem)
{
DV=(System.Data.DataRowView)e.Item.DataItem;
System.Web.UI.WebControls.LinkButton lbn;
lbn=(System.Web.UI.WebControls.LinkButton) e.Item.Cells[1].Controls[0];
lbn.Attributes.Add("onclick","return confirm('絋﹚埃赣魁[emp_no:"+DV["emp_no"].ToString().Trim()+"]盾?');"); e.Item.Attributes.Add("style", "bgColor:'#33ff33';");
e.Item.Attributes.Add("onmouseover", "javascript:this.bgColor='#33ff33';");
e.Item.Attributes.Add("onmouseout","javascript:this.bgColor='#00cc99';");
<tr style="background-color:#E7E7FF">
另一行,是
<tr style="background-color:#7E7EFF">
我现在想在ItemDataBound事件里取出tr的background-color,然后添加
e.Item.Attributes.Add("onmouseout","javascript:this.bgColor='取出来的颜色值'")
但是死活取不出正确的tr的background-color
有什么办法吗?
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
e.Item.Attributes.Add("onmouseover", "this.style.backgroundColor='Silver'")
e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='white'") End If
End Sub
{
DataGridTableStyle ts1 = new DataGridTableStyle();
ts1.MappingName = "Customers";
// Set other properties.
ts1.AlternatingBackColor = Color.LightGray; /* Add a GridColumnStyle and set its MappingName
to the name of a DataColumn in the DataTable.
Set the HeaderText and Width properties. */
DataGridColumnStyle boolCol = new DataGridBoolColumn();
boolCol.MappingName = "Current";
boolCol.HeaderText = "IsCurrent Customer";
boolCol.Width = 150;
ts1.GridColumnStyles.Add(boolCol);
// Add a second column style.
DataGridColumnStyle TextCol = new DataGridTextBoxColumn();
TextCol.MappingName = "custName";
TextCol.HeaderText = "Customer Name";
TextCol.Width = 250;
ts1.GridColumnStyles.Add(TextCol); /* Add the DataGridTableStyle instances to
the GridTableStylesCollection. */
myDataGrid.TableStyles.Add(ts1);
}
设置颜色代码: ts1.AlternatingBackColor = Color.LightGray;