簡體   English   中英

Gridview項目模板DropDownList已啟用

[英]Gridview Itemtemplate DropDownList Enabled

我希望僅在單擊Gridview上的編輯鏈接后禁用DropDownList並啟用它。 到目前為止,它顯示在編輯鏈接之前和之后禁用的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;
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM