【发布时间】:2010-05-09 04:44:03
【问题描述】:
我的 aspx 页面上有一个表单视图,其中包含使用表格排列的各种控件。 我需要根据编辑模式中的角色启用或禁用 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模式改变时发生。
谁能给我合适的解决方案?
感谢您分享您的时间。
【问题讨论】:
标签: asp.net formview edititemtemplate