gpt4 book ai didi

c# - Gridview Itemtemplate DropDownList 已启用

转载 作者:太空宇宙 更新时间:2023-11-03 21:09:32 25 4
gpt4 key购买 nike

我希望禁用 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。绑定(bind)数据后必须启用控件,例如在 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;
}
}

关于c# - Gridview Itemtemplate DropDownList 已启用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38640544/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com