我希望DropDownList
被禁用,并且只有在点击Gridview
上的修改链接后启用它。截至目前,它显示在编辑链接之前和之后禁用DropDownList
。
代码:
<asp:DropDownList ID="DropDownList1" runat="server" Height="30px" Width="190px" SelectedValue='<%# Eval("FAQGroup") %>' Enabled="false" >
<asp:ListItem Value="Most asked FAQ"></asp:ListItem>
<asp:ListItem Value="Normal FAQ"></asp:ListItem>
</asp:DropDownList>
aspx.cs
protected void gvFAQ_RowEditing(object sender, GridViewEditEventArgs e)
{
gvFAQ.Columns[3].Visible = true;
DropDownList DDL= (DropDownList)gvFAQ.Rows[e.NewEditIndex].FindControl("DropDownList1");
DDL.Enabled = true;
gvFAQ.EditIndex = e.NewEditIndex;
bind();
}
答案 0 :(得分:4)
当您在bind
事件处理程序的末尾调用RowEditing
时,GridView将被清除并重新填充,并在每一行中创建一个新的DropDownList。绑定数据后必须启用控件,例如在RowDataBound
事件处理程序中:
protected void gvFAQ_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList ddl = e.Row.FindControl("DropDownList1") as DropDownList;
ddl.Enabled = e.Row.RowIndex == gvFAQ.EditIndex;
}
}