Gridview Itemtemplate DropDownList 已启用
Gridview Itemtemplate DropDownList Enabled
我希望 DropDownList
被禁用,只有在我点击 Gridview
上的编辑 link 后才能启用它。截至目前,它显示 DropDownList
在编辑 link 之前和之后被禁用。
代码:
<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;
}
}
我希望 DropDownList
被禁用,只有在我点击 Gridview
上的编辑 link 后才能启用它。截至目前,它显示 DropDownList
在编辑 link 之前和之后被禁用。
代码:
<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;
}
}