Confused with Controls

  • Thread starter Thread starter encoad
  • Start date Start date
E

encoad

Hi everybody, I'm hoping you can help me understand why this doesn't
work, and perhaps someone can suggest a way for me to solve my problem.
Essentially, I'm trying to add a row with a single cell twice in a
table. Both cells are identical and therefore I don't want to
duplicate everything in the code. My function determines at runtime if
there should be two identical cells or just a single cell. Here is
some sample code, which only displays the contents of a single cell.

protected void Page_Load(object sender, EventArgs e)
{
Table atable = new Table();
TableRow arow = new TableRow();
TableCell acell = new TableCell();
HyperLink alink = new HyperLink();

alink.NavigateUrl = "aaaaaaaaaa";
alink.Text = "aaaaaaaaaaaaaaaaaaaaaaa";

acell.Controls.Add(alink);


arow = new TableRow();
arow.Controls.Add(acell);
atable.Controls.Add(arow);

arow = new TableRow();
arow.Controls.Add(acell);
atable.Controls.Add(arow);

Page.Controls.Add(atable);
}

Now from what I gather, when I do a object.Controls.Add(object) it is
infact moving the object to the new control. So how do I go about
putting the contents of a cell into two different rows in a table? My
exact application is that I want my users to have the option to have a
combination of [menu] - {Gallery Picture} - [menu], with the choices of
displaying the menu on Top, Bottom or Top&Bottom at the same time.

Any help would be appreciated,
Thanks,
Nicholas
 
Encoad,

You are never moving an object, as long as it exist it stays for ever on the
same place.
What you are doing is playing with references to it.
You can set hundred times a reference to it. To explain with some code

\\\
Object myObject = new Object(); ///whatever class
Object myOtherObject = myObject; ///this is a reference to the same object
ArrayList myArray = new ArrayList();
myArray.Add(myOtherObject);
///therefore the same object is twice referenced in the arraylist
myArray.Add(myObject);
///

I hope this help,

Cor
 
Hi Cor, thanks for the reply.

So why is it that my code does not work? Why am I unable to add the
link into two different cells and those cells into two different rows
into the same table? Compile the code and you'll see.

Thanks again,
Nicholas
Encoad,

You are never moving an object, as long as it exist it stays for ever on the
same place.
What you are doing is playing with references to it.
You can set hundred times a reference to it. To explain with some code

\\\
Object myObject = new Object(); ///whatever class
Object myOtherObject = myObject; ///this is a reference to the same object
ArrayList myArray = new ArrayList();
myArray.Add(myOtherObject);
///therefore the same object is twice referenced in the arraylist
myArray.Add(myObject);
///

I hope this help,

Cor

Hi everybody, I'm hoping you can help me understand why this doesn't
work, and perhaps someone can suggest a way for me to solve my problem.
Essentially, I'm trying to add a row with a single cell twice in a
table. Both cells are identical and therefore I don't want to
duplicate everything in the code. My function determines at runtime if
there should be two identical cells or just a single cell. Here is
some sample code, which only displays the contents of a single cell.

protected void Page_Load(object sender, EventArgs e)
{
Table atable = new Table();
TableRow arow = new TableRow();
TableCell acell = new TableCell();
HyperLink alink = new HyperLink();

alink.NavigateUrl = "aaaaaaaaaa";
alink.Text = "aaaaaaaaaaaaaaaaaaaaaaa";

acell.Controls.Add(alink);


arow = new TableRow();
arow.Controls.Add(acell);
atable.Controls.Add(arow);

arow = new TableRow();
arow.Controls.Add(acell);
atable.Controls.Add(arow);

Page.Controls.Add(atable);
}

Now from what I gather, when I do a object.Controls.Add(object) it is
infact moving the object to the new control. So how do I go about
putting the contents of a cell into two different rows in a table? My
exact application is that I want my users to have the option to have a
combination of [menu] - {Gallery Picture} - [menu], with the choices of
displaying the menu on Top, Bottom or Top&Bottom at the same time.

Any help would be appreciated,
Thanks,
Nicholas
 
EnCoad,

It is in my idea strange, because in my idea this is something the same.

\\\
object Whatever = new object();
Whatever = "Whatever";
TableCell acel1 = new TableCell();
TableCell acel2 = new TableCell();
acel1.Text = Whatever.ToString();
acel2.Text = Whatever.ToString();
TableRow arow = new TableRow();
arow.Cells.Add(acel1);
Table atable = new Table();
atable.Controls.Add(arow);
arow = new TableRow();
arow.Cells.Add(acel2);
atable.Controls.Add(arow);
Page.Controls.Add(atable);
//
And this goes very nice while it is two times referencing the same object
Whatever.

As well I was not able to debug it because the quickview did give
information about cells which are not in that class.

Sorry

Cor


Hi Cor, thanks for the reply.

So why is it that my code does not work? Why am I unable to add the
link into two different cells and those cells into two different rows
into the same table? Compile the code and you'll see.

Thanks again,
Nicholas
Encoad,

You are never moving an object, as long as it exist it stays for ever on
the
same place.
What you are doing is playing with references to it.
You can set hundred times a reference to it. To explain with some code

\\\
Object myObject = new Object(); ///whatever class
Object myOtherObject = myObject; ///this is a reference to the same
object
ArrayList myArray = new ArrayList();
myArray.Add(myOtherObject);
///therefore the same object is twice referenced in the arraylist
myArray.Add(myObject);
///

I hope this help,

Cor

Hi everybody, I'm hoping you can help me understand why this doesn't
work, and perhaps someone can suggest a way for me to solve my problem.
Essentially, I'm trying to add a row with a single cell twice in a
table. Both cells are identical and therefore I don't want to
duplicate everything in the code. My function determines at runtime if
there should be two identical cells or just a single cell. Here is
some sample code, which only displays the contents of a single cell.

protected void Page_Load(object sender, EventArgs e)
{
Table atable = new Table();
TableRow arow = new TableRow();
TableCell acell = new TableCell();
HyperLink alink = new HyperLink();

alink.NavigateUrl = "aaaaaaaaaa";
alink.Text = "aaaaaaaaaaaaaaaaaaaaaaa";

acell.Controls.Add(alink);


arow = new TableRow();
arow.Controls.Add(acell);
atable.Controls.Add(arow);

arow = new TableRow();
arow.Controls.Add(acell);
atable.Controls.Add(arow);

Page.Controls.Add(atable);
}

Now from what I gather, when I do a object.Controls.Add(object) it is
infact moving the object to the new control. So how do I go about
putting the contents of a cell into two different rows in a table? My
exact application is that I want my users to have the option to have a
combination of [menu] - {Gallery Picture} - [menu], with the choices of
displaying the menu on Top, Bottom or Top&Bottom at the same time.

Any help would be appreciated,
Thanks,
Nicholas
 
Back
Top