473,396 Members | 1,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Object reference not set to an instance of an object.-i got null value of checkbox ar

satiss7pwr
Expand|Select|Wrap|Line Numbers
  1. public CheckBox[] cb = null;
  2. int z=0;
  3. protected void Page_Load(object sender, EventArgs e)
  4. {
  5.     if (!IsPostBack)
  6.         {
  7.         cb = new CheckBox[count - k];
  8.         //Database code.........
  9.         while (dr.Read())//read data from access database
  10.                 {
  11.             cb[z] = new CheckBox();
  12.                     cb[z].Text = dr["Member_Name"].ToString();
  13.                         Panel2.Controls.Add(cb[z]);
  14.                         Panel2.Controls.Add(new LiteralControl("</br>"));
  15.                         z = z + 1;
  16.         }
  17.     }
  18. }
  19. protected void Button6_Click(object sender, EventArgs e)
  20. {
  21.         for (int x = 0; x < cb.Length; x++)//ERROR IS HERE:Object reference not set to an instance of an object.
  22.         {
  23.         //processing check boxes    
  24.     }
  25. }
Jan 19 '10 #1
2 1768
tlhintoq
3,525 Expert 2GB
You made an array for checkboxes, but you did not initialize each element of that array. You need to make a checkbox for each element and assign it to the element.
Jan 19 '10 #2
Frinavale
9,735 Expert Mod 8TB
Better yet, use a CheckBoxList control.

All you'll have to do is retrieve the data from your database, specify that the data table returned from this is to be used as the DataSource for the CheckBoxList control. Then specify what field should be used as the "value" (using the CheckBoxList.DataValueField property ) and what field should be used for the "text" (using the CheckBoxList.DataTextField property)....and then call the CheckBoxList.DataBind method to bind the data source to the CheckBoxList.

-Frinny
Jan 19 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Bijay Kumar | last post by:
Hi Guys, I was going through the source code of Object.cs in rotor. What I found is Equals() implemented as follows: public extern virtual bool Equals(Object obj); What I don't...
16
by: sneill | last post by:
How is it possible to take the value of a variable (in this case, MODE_CREATE, MODE_UPDATE, etc) and use that as an object property name? In the following example I want 'oIcon' object to have...
8
by: ST | last post by:
Hello everyone, Can anyone help me with this error above when I debug my web app project in vstudio.net?? I can't figure it out! It was working fine for months, and now all of a sudden it's not!!...
3
by: Ross McLean | last post by:
Hi all, I've been teaching myself C# for a new project at work. I have a bit of a background in c++ and java but never been what you could call a guru. I'm having some strange things happening...
16
by: anonymous.user0 | last post by:
The way I understand it, if I have an object Listener that has registered as a listener for some event Event that's produced by an object Emitter, as long as Emitter is still allocated Listener...
12
by: Andrew Poulos | last post by:
With the following code I can't understand why this.num keeps incrementing each time I create a new instance of Foo. For each instance I'm expecting this.num to alert as 1 but keeps incrementing. ...
7
by: TS | last post by:
I was under the assumption that if you pass an object as a param to a method and inside that method this object is changed, the object will stay changed when returned from the method because the...
6
by: Shailen Sukul | last post by:
Observed a weird behaviour with object references. See code listing below: using System; using System.Collections.Generic; using System.Text; namespace PointerExceptionTest { /*
3
by: User1014 | last post by:
A global variable is really just a property of the "Global Object", so what does that make a function defined in the global context? A method of the Global Object? ...
2
by: Ralph | last post by:
Hi I don't understand why it's not working: function schedule(imTop){ this.tdImagesTop = imTop; } schedule.prototype.selectEl = function() { alert(this.tdImagesTop);
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.