dynamic object name

  • Thread starter Thread starter Trevor Hartman
  • Start date Start date
T

Trevor Hartman

Hi,

I need to refer to my objects dynamically. I have a 7 table cells (sunCell,
monCell, tueCell....). I am looping through some data, checking its date
and adding it to the correct cell. I want to be able to do something like:

string day;
foreach ...
{
day = getShortDay(someDateTime);
[day + "Cell"].Controls.Add(new LiteralControl("put some content in this
cell.."));
}

Is there anyway to do this?

thank you - Trevor
 
Why not just using an enumerator and refer to the tables cell collection?
Once you have a reference to the tablecell object you can add to it's
controls collection.
 
The table is dynamic, and I just want 7 individual table cells, and create a
new instance every time I have a new row. how would I do an enumerator in
this case??

its like this:
TableRow row = new TableRow();

TableCell sunCell = new TableHeaderCell();
sunCell.Text = "Sun";
TableCell monCell = new TableHeaderCEll();
monCell.Text = "Sun";
.....
.....

foreach (DataInfo DateItem in DataCollection) // loop through the event data
{
[getShortDayName(DataInfo._Date) + "Cell"].Controls.Add(new
LiteralControl("content"));
...
...
...
}

string getShortDayName(DateTime Date)
{
// some code to return short day name as a string
}

with this setup, can I still use enumeration, or does anyone have any other
ideas?

Thanks,
Trevor Hartman

Jay Pondy said:
Why not just using an enumerator and refer to the tables cell collection?
Once you have a reference to the tablecell object you can add to it's
controls collection.

Trevor Hartman said:
Hi,

I need to refer to my objects dynamically. I have a 7 table cells (sunCell,
monCell, tueCell....). I am looping through some data, checking its date
and adding it to the correct cell. I want to be able to do something like:

string day;
foreach ...
{
day = getShortDay(someDateTime);
[day + "Cell"].Controls.Add(new LiteralControl("put some content in this
cell.."));
}

Is there anyway to do this?

thank you - Trevor
 
thanks a lot for your help! i've never done enumeration so i'm reading up
on it now.

-Trevor

Jay Pondy said:
Create the row and then enumerate Sun - Sat adding a cell for each and
at the same time query the data source to see if you need to add a
literal control for that days cell contents.

Trevor said:
The table is dynamic, and I just want 7 individual table
cells, and create a
new instance every time I have a new row. how would I do
an enumerator in
this case??

its like this:
TableRow row = new TableRow();

TableCell sunCell = new TableHeaderCell();
sunCell.Text = "Sun";
TableCell monCell = new TableHeaderCEll();
monCell.Text = "Sun";
....
....

foreach (DataInfo DateItem in DataCollection) // loop
through the event data
{
[getShortDayName(DataInfo._Date) + "Cell"].Controls.Add(new
LiteralControl("content"));
...
...
...
}

string getShortDayName(DateTime Date)
{
// some code to return short day name as a string
}

with this setup, can I still use enumeration, or does
anyone have any other
ideas?

Thanks,
Trevor Hartman

Jay Pondy said:
Why not just using an enumerator and refer to the tables
cell collection?
Once you have a reference to the tablecell object you can
add to it's
controls collection.

Hi,

I need to refer to my objects dynamically. I have a 7 table cells
(sunCell,
monCell, tueCell....). I am looping through some data,
checking its date
and adding it to the correct cell. I want to be able to
do something
like:

string day;
foreach ...
{
day = getShortDay(someDateTime);
[day + "Cell"].Controls.Add(new LiteralControl("put
some content in
this
cell.."));
}

Is there anyway to do this?

thank you - Trevor
 
ok i read up on enumeration and don't really understand what you mean by
enumerating sun - sat. also, i don't want to loop through my datacollection
98 times, which is how many cells there are. what I am doing now is
creating the table giving each cell a unique ID (date + hour). if you want
to see the table, here it is:
http://www.futureshirts.com/calendar/weekView.aspx?SelectedDate=6/18/2003 12:00:00 AM

wouldn't it be a better idea to just loop through the data once after the
table is created, find the cell that matches the event by date + hour, then
add the event to that cell? the only problem i'm having is referencing the
cell. I could do a FindControl, but I don't really know how to use the
results, since it is a control. I always get the "Object reference not set
to an instance of an object". what do you think?

thanks - trevor


Jay Pondy said:
Create the row and then enumerate Sun - Sat adding a cell for each and
at the same time query the data source to see if you need to add a
literal control for that days cell contents.

Trevor said:
The table is dynamic, and I just want 7 individual table
cells, and create a
new instance every time I have a new row. how would I do
an enumerator in
this case??

its like this:
TableRow row = new TableRow();

TableCell sunCell = new TableHeaderCell();
sunCell.Text = "Sun";
TableCell monCell = new TableHeaderCEll();
monCell.Text = "Sun";
....
....

foreach (DataInfo DateItem in DataCollection) // loop
through the event data
{
[getShortDayName(DataInfo._Date) + "Cell"].Controls.Add(new
LiteralControl("content"));
...
...
...
}

string getShortDayName(DateTime Date)
{
// some code to return short day name as a string
}

with this setup, can I still use enumeration, or does
anyone have any other
ideas?

Thanks,
Trevor Hartman

Jay Pondy said:
Why not just using an enumerator and refer to the tables
cell collection?
Once you have a reference to the tablecell object you can
add to it's
controls collection.

Hi,

I need to refer to my objects dynamically. I have a 7 table cells
(sunCell,
monCell, tueCell....). I am looping through some data,
checking its date
and adding it to the correct cell. I want to be able to
do something
like:

string day;
foreach ...
{
day = getShortDay(someDateTime);
[day + "Cell"].Controls.Add(new LiteralControl("put
some content in
this
cell.."));
}

Is there anyway to do this?

thank you - Trevor
 
Sorry man, I misunderstood what you were trying to do.

Since you know what each row and cell in the table represent as far as
time is concerned go ahead and create the entire table and then loop
through your dataset as you stated. Based on the time stamp from your
data you should be able to determine which row and cell needs to be
referenced and you can access it as follows:

TimeTable.Rows(iRow).Cells(iCell).Controls.Add()

Trevor said:
ok i read up on enumeration and don't really understand
what you mean by
enumerating sun - sat. also, i don't want to loop through
my datacollection
98 times, which is how many cells there are. what I am doing now is
creating the table giving each cell a unique ID (date +
hour). if you want
to see the table, here it is:
http://www.futureshirts.com/calendar/weekView.aspx?SelectedDate=6/18/2003 12:
00:00%20AM

wouldn't it be a better idea to just loop through the data
once after the
table is created, find the cell that matches the event by
date + hour, then
add the event to that cell? the only problem i'm having
is referencing the
cell. I could do a FindControl, but I don't really know
how to use the
results, since it is a control. I always get the "Object
reference not set
to an instance of an object". what do you think?

thanks - trevor

Jay Pondy said:
Create the row and then enumerate Sun - Sat adding a cell
for each and
at the same time query the data source to see if you need to add a
literal control for that days cell contents.

Trevor said:
The table is dynamic, and I just want 7 individual table
cells, and create a
new instance every time I have a new row. how would I do
an enumerator in
this case??

its like this:
TableRow row = new TableRow(); etc..
Why not just using an enumerator and refer to the tables
cell collection?
Once you have a reference to the tablecell object you can
add to it's
controls collection.

Hi,

I need to refer to my objects dynamically. I have a 7
table cells
(sunCell,
monCell, tueCell....). I am looping through some data,
checking its
date
and adding it to the correct cell. I want to be able to
do something
like:

string day;
foreach ...
{
day = getShortDay(someDateTime);
[day + "Cell"].Controls.Add(new LiteralControl("put
some content in
this
cell.."));
}

Is there anyway to do this?

thank you - Trevor
 
i finally got it working! thanks a lot for your help

-trevor

Jay Pondy said:
Sorry man, I misunderstood what you were trying to do.

Since you know what each row and cell in the table represent as far as
time is concerned go ahead and create the entire table and then loop
through your dataset as you stated. Based on the time stamp from your
data you should be able to determine which row and cell needs to be
referenced and you can access it as follows:

TimeTable.Rows(iRow).Cells(iCell).Controls.Add()

Trevor said:
ok i read up on enumeration and don't really understand
what you mean by
enumerating sun - sat. also, i don't want to loop through
my datacollection
98 times, which is how many cells there are. what I am doing now is
creating the table giving each cell a unique ID (date +
hour). if you want
to see the table, here it is:
http://www.futureshirts.com/calendar/weekView.aspx?SelectedDate=6/18/2003 12:
00:00%20AM

wouldn't it be a better idea to just loop through the data
once after the
table is created, find the cell that matches the event by
date + hour, then
add the event to that cell? the only problem i'm having
is referencing the
cell. I could do a FindControl, but I don't really know
how to use the
results, since it is a control. I always get the "Object
reference not set
to an instance of an object". what do you think?

thanks - trevor

Jay Pondy said:
Create the row and then enumerate Sun - Sat adding a cell
for each and
at the same time query the data source to see if you need to add a
literal control for that days cell contents.

Trevor Hartman wrote:
The table is dynamic, and I just want 7 individual table
cells, and create a
new instance every time I have a new row. how would I do
an enumerator in
this case??

its like this:
TableRow row = new TableRow(); etc..
Why not just using an enumerator and refer to the tables
cell collection?
Once you have a reference to the tablecell object you can
add to it's
controls collection.

Hi,

I need to refer to my objects dynamically. I have a 7
table cells
(sunCell,
monCell, tueCell....). I am looping through some data,
checking its
date
and adding it to the correct cell. I want to be able to
do something
like:

string day;
foreach ...
{
day = getShortDay(someDateTime);
[day + "Cell"].Controls.Add(new LiteralControl("put
some content in
this
cell.."));
}

Is there anyway to do this?

thank you - Trevor
 
Back
Top