1
我在我的aspx頁面上有一個formview,其中包含使用table排列的各種控件。 有一個DDL「cboClients」,我需要根據編輯模式中的角色啓用或禁用。如何從FormView的EditItemTemplate訪問下拉列表
這裏的問題是,我無法使用FindControl()方法獲得該控件。
我曾嘗試下面的代碼 -
DropDownList ddl = null;
if (FormView1.Row != null)
{
ddl = (DropDownList)FormView1.Row.FindControl("cboClients");
ddl.Enabled=false;
}
即使我AVE使用相同的控制的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的模式是這樣的數據綁定事件只發生一次,但不改變。
任何人都可以提供適當的解決方案嗎?
感謝分享你的時間。
感謝拉吉,但我也使用了。 – IrfanRaza 2010-05-09 05:04:21
謝謝Raj,那對我有效。但你能說出鑄造和使用「as」操作符有什麼區別嗎? – IrfanRaza 2010-05-09 06:38:19
as運算符就像一個強制轉換,除了在轉換失敗時產生空值而不是引發異常。 http://msdn.microsoft.com/en-us/library/cscsdfbt(vs.71).aspx – 2010-05-09 06:44:12