我的 aspx 页面上有一个 formview,其中包含使用表格排列的各种控件。有一个 DDL“cboClients”,我需要根据编辑模式中的角色启用或禁用它。
这里的问题是我无法使用 FindControl() 方法获得该控件。
我试过以下代码 -
DropDownList ddl = null;
if (FormView1.Row != null)
{
ddl = (DropDownList)FormView1.Row.FindControl("cboClients");
ddl.Enabled=false;
}
即使我使用了同一个控件的 DataBound 事件 -
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 模式更改时发生。
谁能给我适当的解决方案?
感谢您分享您的时间。