更改行颜色Datagridview [英] Change Row Color 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屋!