网格视图项目模板下拉列表已启用
本文关键字:下拉列表 启用 视图 项目 网格 | 更新日期: 2023-09-27 17:59:02
我希望禁用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();
}
当您在RowEditing
事件处理程序结束时调用bind
时,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;
}
}