0

我试图更改 gridview 行中的 dropdownlist.enabled 。

我写了这个代码块。

            if (isEdit && index == e.Row.RowIndex)
            {
                foreach (GridViewRow item in GridView1.Rows)
                {
                    if (item.RowIndex == index)
                    {
                        DataRowView rowView2 = (DataRowView)item.DataItem;
                        DDL = (DropDownList)item.FindControl("ddlLocation");
                        DDL.Enabled = true;
                        isEdit = false;
                    }
                }

             }

并从 GridView1_RowEditing 获取 isEdit

喜欢 :

  isEdit = true;

并从行命令中获取索引,例如:

        if (e.CommandName == "Edit")
        {
            index = Convert.ToInt32(e.CommandArgument);
        }

有人可以帮助我吗?

4

1 回答 1

1

您应该能够将代码简化为:

if (isEdit)
{
    DropDownList DDL = (DropDownList)GridView1.Rows[index].FindControl("ddlLocation");
    DDL.Enabled = true;
    isEdit = false;
 }
于 2012-04-26T13:46:22.577 回答