PC Review


Reply
Thread Tools Rate Thread

Confused with Controls

 
 
encoad@gmail.com
Guest
Posts: n/a
 
      2nd Sep 2006
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

 
Reply With Quote
 
 
 
 
Cor Ligthert [MVP]
Guest
Posts: n/a
 
      2nd Sep 2006
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

<(E-Mail Removed)> schreef in bericht
news:(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
encoad@gmail.com
Guest
Posts: n/a
 
      2nd Sep 2006
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

Cor Ligthert [MVP] wrote:
> 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
>
> <(E-Mail Removed)> schreef in bericht
> news:(E-Mail Removed)...
> > 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
> >


 
Reply With Quote
 
Cor Ligthert [MVP]
Guest
Posts: n/a
 
      2nd Sep 2006
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


<(E-Mail Removed)> schreef in bericht
news:(E-Mail Removed)...
> 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
>
> Cor Ligthert [MVP] wrote:
>> 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
>>
>> <(E-Mail Removed)> schreef in bericht
>> news:(E-Mail Removed)...
>> > 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
>> >

>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ViewState got confused between two user controls in same parent ct =?Utf-8?B?TG91aXNl?= Microsoft ASP .NET 6 12th Oct 2005 07:53 PM
Confused about Server side/ client side and which controls to use msnews Microsoft ASP .NET 0 27th May 2005 12:01 AM
I'm confused about Active X controls charles kuchar Windows XP General 6 27th Oct 2004 02:24 PM
Confused, need valid logon for OE, confused.. Rob Windows XP General 1 3rd Nov 2003 02:15 AM
Confused about bound controls update of dataset STom Microsoft ADO .NET 0 30th Oct 2003 12:18 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:10 AM.