我在每一行都有带有下拉列表模板字段的gridview..所有下拉列表都设置为默认值“选择”。当我从下拉列表中选择任何值时,它会改变下面第三行的颜色但是当我重新选择“选择”选项颜色仍然存在于第 3 行。我不需要它。应该将其更改为 gridview 的默认颜色,即白色。这是我的代码。
protected void GridView1_SelectedIndexChanged(object sender,EventArgs e)
{
DropDownList ddl = (DropDownList)sender;
GridViewRow row = (GridViewRow)ddl.NamingContainer;
int g = row.RowIndex + 3;
int current_row_index = row.RowIndex;
foreach (GridViewRow gvRow in GridView1.Rows)
{
gvRow.BackColor = Color.White;
if (gvRow.FindControl("dropdownid") != null && gvRow.RowIndex != current_row_index)
{
((DropDownList)gvRow.FindControl("dropdownid")).SelectedIndex = 0;
}
}
GridView1.Rows[g].BackColor = Color.Red;
}