How to access drop down list from EditItemTemplate of FormView

Posted by IrfanRaza on Stack Overflow See other posts from Stack Overflow or by IrfanRaza
Published on 2010-05-09T04:44:03Z Indexed on 2010/05/09 4:48 UTC
Read the original article Hit count: 446

Hello friends, 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.

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about formview