Link to home
Start Free TrialLog in
Avatar of pr_wainwright
pr_wainwright

asked on

FormView ModeChanged Event (ASP.NET C#)

Hi,
     I have the following code where I wish to access a DropDownList box on FormView1's Edit Template after the Edit button is clicked on the FormView's Item template, but I get a NullReferenceException when the FormView's mode changes to Edit. Any help appreciated. Thanks Paul.

protected void FormView1_ModeChanged(object sender, EventArgs e)
    {
        if (FormView1.CurrentMode == FormViewMode.ReadOnly)
        {  
            laMessageTimes.Text = "Read Only Mode";
        }

        if (FormView1.CurrentMode == FormViewMode.Edit) //Edit Command button clicked
        {
            //ddlClientsE is in FormView1's Edit Template
            DropDownList ClientDDL = (DropDownList)FormView1.FindControl("ddlClientsE");
           
             //NullReferenceException Here!
            ClientDDL.Items.Add("BG");

            laMessageTimes.Text = "Edit Mode";
        }
    }
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pr_wainwright
pr_wainwright

ASKER

CodeCruiser,
                    I have used moved the code into the SQLDataSources DataBinding handler & it now works fine. I will accept your solution as you were my only reply.

Thanks for the help.

Paul.