如何从FormView的EditiTemTemplate访问下拉列表
-
04-10-2019 - |
题
我在我的ASPX页面上有一个FormView,其中包含使用表格排列的各种控件。有一个DDL“ cboclients”,我需要根据编辑模式中的角色来启用或禁用。
这里的问题是我无法使用FindControl()方法获得该控件。
我尝试了遵循代码 -
DropDownList ddl = null;
if (FormView1.Row != null)
{
ddl = (DropDownList)FormView1.Row.FindControl("cboClients");
ddl.Enabled=false;
}
甚至我都使用了相同控件的数据库事件 -
protected void cboClients_DataBound(object sender, EventArgs e)
{
if (FormView1.CurrentMode == FormViewMode.Edit)
{
if ((Session["RoleName"].ToString().Equals("Clients")) || (Session["RoleName"].ToString().Equals("Suppliers")))
{
DropDownList ddl = (DropDownList)sender;
ddl.Enabled = false;
}
}
}
但是,此数据库事件仅发生一次,但在更改FormView模式时不会发生。
谁能提供适当的解决方案?
感谢您分享您的时间。
解决方案
尝试模拟事件。http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.formview.modechanged.aspx
更新..
试试这个
DropDownList ddl = FormView1.FindControl("cboClients") as DropDownList;
if (ddl != null) {
ddl.Enabled=false;
}
不隶属于 StackOverflow