views:

23

answers:

1
 public partial class Table_Traversing : System.Web.UI.Page
 {
 Table table1 = new Table();


 TableRow table_row1 = new TableRow();

 TableCell table_cell1 = new TableCell();

 TableCell table_cell2 = new TableCell();

 Label The_text = new Label();

 CheckBox checkmate = new CheckBox();

 Button button1 = new Button();



 public void Page_Init(object sender, EventArgs e)
 {
     //Table asdasd = new Table();
 }


 protected void Page_Load(object sender, EventArgs e)
 {


    The_text.Text = "This is the text :-)";

    checkmate.Checked = false;

    table_cell2.Controls.Add(checkmate);

    table_cell1.Controls.Add(The_text);

    table_row1.Controls.AddAt(0, table_cell1);

    table_row1.Controls.AddAt(1, table_cell2);

    table1.Rows.Add(table_row1);


    button1.Text = "click me to export the value";

    form1.Controls.AddAt(0, table1);
    form1.Controls.AddAt(0, button1);


    CheckBox check_or_not = new CheckBox();

    check_or_not = (CheckBox)table1.FindControl("checkmate");

    Response.Write(check_or_not.Checked.ToString());


    button1.Click += new EventHandler(button1_Click);





 }

The error is

Object reference not set to an instance of an object.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 59: check_or_not = (CheckBox) table1.FindControl("checkmate");

Line 60:

Line 61: Response.Write(check_or_not.Checked.ToString());

Line 62:

+1  A: 

You have to give the control an ID, if you want to use FindControl ... so you have to add this before invoking FindControl:

checkmate.ID = "checkmate";
Richard Hein
o i thought that the name of the control is the id!! wrong i guess :(
can you please provide a reference, which explains how to retrieve each and every aspect of the table, like the row number, the cell number etc.. thankyou
Maybe if you ask another question ;)
Richard Hein