Solved

FormView ModeChanged Event (ASP.NET C#)

Posted on 2009-04-08
2
977 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

861 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