0

我在每一行都有带有下拉列表模板字段的gridview。当我从下拉列表中选择任何值时,它会改变下面第三行的颜色。但是当我点击另一个下拉列表时,它会改变下面第三行的颜色,但是上一个下拉列表的索引未更改为 0,即“选择”。它仍然显示在最后一个下拉列表中选择的值。我只想在单击下拉列表时,所有其他下拉列表都应索引为 0,即“选择”,除了一个我点击了。我在下拉列表的 Selectedindexchange 事件中执行以下操作:

protected void GridView1_SelectedIndexChanged(object sender,EventArgs e)
    {

        foreach (GridViewRow gvRow in GridView1.Rows)
        {
               int g1 = gvRow.RowIndex;
               GridView1.Rows[g1].BackColor = Color.White;
         }
            DropDownList ddl = (DropDownList)sender;
            GridViewRow row = (GridViewRow)ddl.NamingContainer;
            int g = row.RowIndex + 3;
            int current_row_index = row.RowIndex;
            int pp = GridView1.Rows.Count;
             GridView1.Rows[g].BackColor = Color.Red;
         }
     }

提前致谢。

4

2 回答 2

0

只需将DropdownName.ClearSelection()用于其他每个下拉列表,除了您调用 Selectedindexchange 事件的下拉列表。

于 2012-07-31T08:05:57.263 回答
0

也许是这样的:

     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("nameOfTheDropdown") != null && gvRow.RowIndex != current_row_index)
            {
                ((DropDownList)gvRow.FindControl("nameOfTheDropdown")).SelectedIndex = 0;
            }
        }

        GridView1.Rows[g].BackColor = Color.Red;  
     }

问候

于 2012-07-31T08:09:18.373 回答