Solved

FormView ModeChanged Event (ASP.NET C#)

Posted on 2009-04-08
2
970 Views
Last Modified: 2012-08-14
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";
        }
    }
0
Comment
Question by:pr_wainwright
2 Comments
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 125 total points
ID: 24105183
This means that FindControl is failing to find the ddl from the formview.
0
 
LVL 1

Author Comment

by:pr_wainwright
ID: 24105549
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.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now