Solved

FormView ModeChanged Event (ASP.NET C#)

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

763 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