且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

更改行颜色Datagridview

更新时间:2022-10-14 23:13:52

试试这个:



 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[^]