日期:2014-05-17  浏览次数:20406 次

动态生成的DataGrid如何控制样式?求解
后台纯代码生成的DataGrid,怎么有效控制HeaderStyle、ItemStyle、SelectedItemStyle、AlternatingItemStyle这些属性?

DataGrid dghead = new DataGrid();
dghead.SelectedItemStyle.BackColor = ColorTranslator.FromHtml("#FEE0E0");
dghead.AlternatingItemStyle.BackColor = ColorTranslator.FromHtml("#F4F9FF");
dghead.ItemStyle.Font.Size = 9;
dghead.HeaderStyle.Font.Size = 9;
dghead.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
dghead.HeaderStyle.VerticalAlign = VerticalAlign.Middle;
dghead.HeaderStyle.BackColor = ColorTranslator.FromHtml("#AAD1FE");

这样写不起作用呢?求高手解答。。
asp.net c#

------解决方案--------------------
   protected void lvRegion_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Style.Clear();
                e.Row.Attributes.Add("OnMouseOut", "this.style.backgroundColor='White';this.style.color='#003399'");
                e.Row.Attributes.Add("OnMouseOver", "this.style.backgroundColor='#F7A20B';this.style.color='#F7A20B'");
                if (((LinkButton)e.Row.Cells[0].FindControl("lnkRegion")).CommandArgument.Split('
------解决方案--------------------
')[0] == this.btnSelectRegion.Text)
                {
                    e.Row.CssClass = "girdSelect";
                    e.Row.Cells[0].CssClass = "girdSelect";
                }
            }
        }