更改Datagridview中特殊行的颜色 [英] changing the color of special rows in Datagridview
本文介绍了更改Datagridview中特殊行的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
解决方案
在这里,我正在检查2列作为datetime列.请根据您的网格设计进行更改
受保护的 无效 myGridView_RowDataBound(对象发件人,GridViewRowEventArgs e){ 如果(例如,Row.RowType == DataControlRowType.DataRow) { 如果(Convert.ToDateTime(e.Row.Cells [ 1 ].Text)== DateTime.Now ) { e.Row.BackColor = System.Drawing.Color.Red; } } }
1.使用System.Drawing;
2.在此事件中编写代码
受保护的 void gvReminder_RowCommand(对象发件人,GridViewCommandEventArgs e) { 尝试 { 如果(例如CommandName == " 跨度>) { int 索引= Convert.ToInt32(e.CommandArgument); ViewState [" ] = gvReminder.Rows [Index] .Cells [ true ; 看法(); GridFillReminderDetails(); gvReminder.Rows [Index] .Cells [ 0 ].ForeColor = Color.Red; gvReminder.Rows [Index] .Cells [ 1 ].ForeColor = Color.Red; gvReminder.Rows [Index] .Cells [ 2 ].ForeColor = Color.Red; (((LinkButton)gvReminder.Rows [Index] .Cells [ 3 ].Controls [ 0 ]). ForeColor = Color.Red; gvReminder.Rows [Index] .Cells [ 4 ].ForeColor = Color.Red; } } 捕获 { } }
hi
i have date record in my database.when i want to show the records in datagridview, i want to change the color of some rows that the date record of them is as the same as date of today.how can i do that?
thanks alot
解决方案
Here i am checking 2 column as datetime column. Pls change as per you grid design
protected void myGridView_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { if (Convert.ToDateTime(e.Row.Cells[1].Text)==DateTime.Now) { e.Row.BackColor = System.Drawing.Color.Red; } } }
Hi,
1.using System.Drawing;
2.write code in this event
protected void gvReminder_RowCommand(object sender, GridViewCommandEventArgs e) { try { if (e.CommandName == "subject") { int Index = Convert.ToInt32(e.CommandArgument); ViewState["ReminderId"] = gvReminder.Rows[Index].Cells[1].Text; btnDelete.Visible = true; view(); GridFillReminderDetails(); gvReminder.Rows[Index].Cells[0].ForeColor = Color.Red; gvReminder.Rows[Index].Cells[1].ForeColor = Color.Red; gvReminder.Rows[Index].Cells[2].ForeColor = Color.Red; ((LinkButton)gvReminder.Rows[Index].Cells[3].Controls[0]).ForeColor = Color.Red; gvReminder.Rows[Index].Cells[4].ForeColor = Color.Red; } } catch { } }
这篇关于更改Datagridview中特殊行的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文