Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 26th, 2006, 08:30 PM
Registered User
 
Join Date: Oct 2006
Location: Cheltenham, , United Kingdom.
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default Object reference not set to an instance of an obje

I am creating a set of drop down lists on a page with the following code:

Table table = new Table();
        TableRow trow = new TableRow();
        TableCell tcell = new TableCell();
        DropDownList ddl;
        Label lbl;
        table.ID = "tblItems";
        table.BorderColor = System.Drawing.Color.Blue;
        table.BorderStyle = BorderStyle.Solid;
        table.BorderWidth = 1;

        int i = 0;
        foreach (DataRow row in dtColumns.Rows)
        {
            trow = new TableRow();
            tcell = new TableCell();
            tcell.ID = "Cell" + i.ToString();
            tcell.Width = 120;
            ddl = new DropDownList();
            lbl = new Label();
            lbl.Text = row["Column_Name"].ToString();
            tcell.Controls.Add(lbl);
            trow.Cells.Add(tcell);
            tcell = new TableCell();
            ddl.DataSource = dt;
            ddl.DataTextField = "Choice";
            ddl.DataValueField = "Reference";
            ddl.DataBind();
            ddl.SelectedValue = row["Column_Name"].ToString();
            ddl.ID = "ddlFields" + i.ToString();
            tcell.Controls.Add(ddl);
            trow.Cells.Add(tcell);
            table.Rows.Add(trow);
            i++;
        }
        hidColumns.Value = (--i).ToString();
        plhColumnMatch.Controls.Add(table);
        plhWorksheets.Visible = false;
        plhColumns.Visible = true;

On the page is a button and it OnClick event contains the following code:

for (int i = 0; i <= intColumns; i++)
        {
            DropDownList ddl1 = new DropDownList();
            string strValue;
            Button btn = (Button)Page.FindControl("Button1");
            ddl1 = (DropDownList)plhColumnMatch.FindControl("ddlField s0");
            strValue = ddl1.SelectedValue;

The last piece of code generates the error. I have tired referencing a control (a button) that was added at design time but I get the same. I have tried variations, such as:
strValue = (plhColumnMatch.FindControl("ddlFields0")as DropDownList).SelectedValue;
but I still get the same.

I am using VS2005 with sp1 and it using localhost/http not file

Thanks
Robert
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Object reference not set to an instance of an obje GS C# 2005 3 May 21st, 2007 10:11 AM
Object reference not set to an instance of an obje williadn General .NET 0 January 18th, 2005 05:39 PM
Object reference not set to an instance of an obje bekim Classic ASP Basics 1 August 9th, 2004 01:25 AM
Object reference not set to an instance of an obje DolphinBay VB.NET 2002/2003 Basics 6 June 28th, 2004 03:14 AM



All times are GMT -4. The time now is 01:02 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.