更改行颜色Datagridview [英] Change Row Color Datagridview

查看:76
本文介绍了更改行颜色Datagridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码,当用户点击更新时,会将一个值插入超时列。



默认情况下,超时值为空。



所以当行更新时,如何更改行的列?



< pre lang =c#>标签lblEditEmpName =(标签)EMPLOYEERECORD.Rows [e.RowIndex] .FindControl( lblEditEmpName );
Label lblEditTimeOut =(Label)EMPLOYEERECORD.Rows [e.RowIndex] .FindControl( lblEditTimeOut);


DatabaseModule.SQcon.Open();
string cmdstr = update dbo.RecordEmployee设置TIME_OUT = @ timeout,其中EMPLOYEE_NAME = @ empname;
SqlCommand cmd = new SqlCommand(cmdstr,DatabaseModule.SQcon);

cmd.Parameters.AddWithValue( @ empname,lblEditEmpName.Text );
cmd.Parameters.AddWithValue( @ timeout,DateTime.Now.ToString(< span class =code-string>
T));

cmd.ExecuteNonQuery();
DatabaseModule.SQcon.Close();
EMPLOYEERECORD.EditIndex = -1;

BindData();

解决方案

试试这个:



 DataGridView row = EMPLOYEERECORD.Rows [e.RowIndex]; 
row.DefaultCellStyle.BackColor = Color.Green;


尝试

根据列值 [ ^ ]

C#提示:动态DataGridView行颜色 [ ^ ]

I have the following code, when user clicks update, a value will be inserted to the time out column.

at default, timeout value is null .

so when the row is updated, how do I change the column of the row?

Label lblEditEmpName = (Label)EMPLOYEERECORD.Rows[e.RowIndex].FindControl("lblEditEmpName");
           Label lblEditTimeOut = (Label)EMPLOYEERECORD.Rows[e.RowIndex].FindControl("lblEditTimeOut");


           DatabaseModule.SQcon.Open();
           string cmdstr = "update dbo.RecordEmployee set TIME_OUT=@timeout where    EMPLOYEE_NAME =@empname";
           SqlCommand cmd = new SqlCommand(cmdstr, DatabaseModule.SQcon);

           cmd.Parameters.AddWithValue("@empname", lblEditEmpName.Text);
           cmd.Parameters.AddWithValue("@timeout", DateTime.Now.ToString("T"));

           cmd.ExecuteNonQuery();
           DatabaseModule.SQcon.Close();
           EMPLOYEERECORD.EditIndex = -1;

           BindData();

解决方案

Try this:

DataGridView row = EMPLOYEERECORD.Rows[e.RowIndex];
row.DefaultCellStyle.BackColor = Color.Green;


Try
Change individual DataGridView row colors based on column value[^]
C# Tip : Dynamic DataGridView Row Colors[^]


这篇关于更改行颜色Datagridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆