0

我在每一行都有带有下拉列表模板字段的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;

         }
4

1 回答 1

0

已解决。我对代码进行了以下更改,并且工作正常。

 protected void GridView1_SelectedIndexChanged(object sender,EventArgs e)
    {

       DropDownList ddl = (DropDownList)sender;
        GridViewRow row = (GridViewRow)ddl.NamingContainer;
        int count=0;
        int g = row.RowIndex + 3;
        int current_row_index = row.RowIndex;
        foreach (GridViewRow gvRow in GridView1.Rows)
        {

            gvRow.BackColor = Color.White;
            if (((DropDownList)gvRow.FindControl("dropdownid")).SelectedIndex != 0)
            {
               // GridView1.BackColor = Color.Yellow;
                count++;

                Response.Write("null");

            }

           if (gvRow.FindControl("dropdownid") != null && gvRow.RowIndex != current_row_index)
            {
                ((DropDownList)gvRow.FindControl("dropdownid")).SelectedIndex = 0;
            }
             }



             GridView1.Rows[g].BackColor = Color.Red;
              Response.Write("count="+count);

              if (count == 0)
              {
                  foreach (GridViewRow gvRow in GridView1.Rows)
                  {
                      gvRow.BackColor = Color.White;

                  }

              }

         }
于 2012-07-31T11:35:09.073 回答