By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,526 Members | 2,189 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,526 IT Pros & Developers. It's quick & easy.

Dynamically add a asp:checkbox in a table.

P: n/a
UJ
I have a table that I need to manually generate based on stuff in the
database. I build the actual table string and stuff it into an asp:panel. So
far it works fine. I'm now trying to add a checkbox to each cell so that
whether it's selected or not.

Problem is, I set the code in the cell during page_load but if I look at the
actual HTML, it says <asp:checkbox ..... whereas everything that is
not dynamic is normal html. So apparently the code is not getting translated
into html.

Here's what I'm actually trying to do: we have pictures we put on our
website. We one a day and remove one a day. The customer would like to see a
'calendar' of pictures and select/deselect the ones they receive. This means
that if it's a Tuesday, they would like to see from Tuesday forward. Monday
would be blank. If it's Thursday, Sunday, Monday, Tuesday and Wednesday
would be blank. Like I said I manually created the table and it works (it's
pretty wild code though) but maybe somebody has a better suggestion on doing
it. The only thing I can think of is to retrieve the data, then prepad the
days so they always start with Sunday and hide everything before this day of
the week.

Anybody got any suggestions?

TIA - Jeff.
May 1 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
> Problem is, I set the code in the cell during page_load but if I look at
the actual HTML, it says <asp:checkbox ..... whereas everything that
is not dynamic is normal html. So apparently the code is not getting
translated into html.


How are you adding to the panel? Creating dynamic controls can be a bit
tricky. One thing to keep in mind is that you have to recreate the control
array on every postback; otherwise ASP.NET won't restore the objects (you
won't see them). You also need to do this to keep the viewstate untainted.

Here's an example (not tested)

protected void Page_Init(object sender, EventArgs e)
{
for (int i = 0; i < 20; i++)
{
CheckBox box = new CheckBox();
box.ID = "myBox" + i.ToString();
box.Text = "label " + i.ToString();

Panel1.Controls.Add(box);
}
}

May 1 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.