将颜色添加到gridview行/单元格 [英] Adding color to a gridview row/cell
本文介绍了将颜色添加到gridview行/单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我使用以下代码手动将数据添加到gridview:
Hello all,
I am adding data manually to a gridview with the following code:
DataTable dt = new DataTable();
DataColumn dc = new DataColumn("column1");
DataRow dr = dt.NewRow();
dr["column1"] = "value1";
dt.Rows.AddNew(dr);
myDataGrid.DataSource = dt;
myDataGrid.DataBind();
但我需要知道的是在添加这一行期间我需要这行我指定的不同颜色的gridview。有没有办法可以做到?我正在查看行颜色等属性,但我没有看到它。我也不想在数据绑定时这样做,因为我手动添加值并在随机位置,所以我无法跟踪行索引。如果这是可行的,请告知。
谢谢。
But what I need know is during the addition of this row I need this row of that gridview in a different color that I specify. Is there a way that I can do it? I was looking at the row properties such as backcolor or so but I didnt see it. I also dont want to do it while databound because i am adding the values manually and in random places so I can not keep track of the row index. If this is doable please advise.
Thanks.
推荐答案
在数据表中添加另一列 customRow将值设置为yes,无论您手动添加行。在gridview中添加一个标签(不可见),文本属性设置为customRow。在rowdatabound evend中使用findcontrol方法查找标签的文本,如果是yes,则添加
Add another column in your datatable as "customRow" set its value to yes wherever you add a row manually. In your gridview add a label(invisible) with text property set as "customRow". In rowdatabound evend use findcontrol method to find the text of the label and if it is "yes", add
e.Row.Attributes.Add("style","this.class='your css style'");
这篇关于将颜色添加到gridview行/单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文