Solved

FormView ModeChanged Event (ASP.NET C#)

Posted on 2009-04-08
2
987 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
asp.net web application 3 58
VB.NET Textbox input validation 4 75
Please explain purpose of GZIP 4 82
asp web application 3 55
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

739 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