IrfanRaza
IrfanRaza

Reputation: 3058

How to access drop down list from EditItemTemplate of FormView

I have a formview on my aspx page containing various controls arranged using table. There is a DDL "cboClients" which i need to enable or disabled depending upon role within Edit mode.

The problem here is that i am not able to get that control using FindControl() method.

I have tried following code -

     DropDownList ddl = null;
       if (FormView1.Row != null)
        {
            ddl = (DropDownList)FormView1.Row.FindControl("cboClients");
            ddl.Enabled=false;        
}

Even I ave used the DataBound event of the same control -

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;
            }
        }
    }

But this databound event occurs only once, but not when formview mode is changed.

Can anyone provide me proper solution?

Thanks for sharing your time.

Upvotes: 1

Views: 3313

Answers (1)

Raj Kaimal
Raj Kaimal

Reputation: 8304

Try the ModeChanged event. http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.formview.modechanged.aspx

update..

Try this

DropDownList ddl = FormView1.FindControl("cboClients") as DropDownList;
if (ddl != null) {
  ddl.Enabled=false;        
}

Upvotes: 2

Related Questions