[英]Gridview Itemtemplate DropDownList Enabled
I'd like the DropDownList
to be disabled and enable it only after I click on the edit link on Gridview
. 我希望仅在单击Gridview
上的编辑链接后禁用DropDownList
并启用它。 As of now, it is showing the DropDownList
to be disabled before and after edit link. 到目前为止,它显示在编辑链接之前和之后禁用的DropDownList
。
codes: 代码:
<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 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();
}
When you call bind
at the end of the RowEditing
event handler, the GridView is cleared and refilled, and a new DropDownList is created in each row. 当您在RowEditing
事件处理程序的末尾调用bind
时,将清除并重新填充GridView,并在每行中创建一个新的DropDownList。 The control must be enabled after the data is bound, for example in the RowDataBound
event handler: 绑定数据后必须启用控件,例如在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;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.