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

Adding Html Code dynmically in Placeholder

P: n/a
Hi,

i want to structure two elements (each conists of 1 Label and 1 Textbox) in
an Table. As I use an Content Place Holder, i thought it is possible to add
the table via Controls.add(Literal). Literal consists of standard html code
like <table>, <tr>, etc.. Nevertheless Asp Net generates me now table in
html code, maybe you see my mistake in the code below. Thanks a lot!

_MC_

Literal tableStart = new Literal(); tableStart.Text =
"<table>";

Literal tableStop = new Literal(); tableStop.Text =
"</table>";

Literal rowStart = new Literal(); rowStart.Text = "<tr>";

Literal rowStop = new Literal(); rowStart.Text = "</tr>";

Literal jumpColumnStart = new Literal(); jumpColumnStart.Text = "<td>";


PlaceHolder2_EditableItems.Controls.Add(tableStart ); // <table>

PlaceHolder2_EditableItems.Controls.Add(rowStart); // <tr>

for (int i = 0; i < columnNames.Count; i++) {

lastcount++;

Label infoLabel = new Label();

infoLabel.Text = "test1";
TextBox myValTextBox = new TextBox();

myValTextBox.Text = "test2"

PlaceHolder2_EditableItems.Controls.Add(jumpColumn Start); // <td>

PlaceHolder2_EditableItems.Controls.Add(infoLabel) ;

PlaceHolder2_EditableItems.Controls.Add(jumpColumn Start); // <td>

PlaceHolder2_EditableItems.Controls.Add(myValTextB ox);

if (lastcount == tableColumns)

{

PlaceHolder2_EditableItems.Controls.Add(rowStop); // </tr>

PlaceHolder2_EditableItems.Controls.Add(rowStart); // <tr>

lastcount = 0;

}
}

PlaceHolder2_EditableItems.Controls.Add(tableStop) ;


Apr 6 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
I don't believe it will work as you expect because you are adding the same
object repeatedly. That will confuse the control you are adding it to such
as the placeholder. Your best bet is to create the
literal controls that control the start and stop of the table cells within
the loop. That would limit how often you add the same control to the
placeholder because it will be a new literal control each time it goes
through the loop.
--
Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006

"_MC_" <mc@localhostwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
Hi,

i want to structure two elements (each conists of 1 Label and 1 Textbox)
in an Table. As I use an Content Place Holder, i thought it is possible to
add the table via Controls.add(Literal). Literal consists of standard html
code like <table>, <tr>, etc.. Nevertheless Asp Net generates me now table
in html code, maybe you see my mistake in the code below. Thanks a lot!

_MC_

Literal tableStart = new Literal(); tableStart.Text =
"<table>";

Literal tableStop = new Literal(); tableStop.Text =
"</table>";

Literal rowStart = new Literal(); rowStart.Text =
"<tr>";

Literal rowStop = new Literal(); rowStart.Text =
"</tr>";

Literal jumpColumnStart = new Literal(); jumpColumnStart.Text =
"<td>";


PlaceHolder2_EditableItems.Controls.Add(tableStart ); // <table>

PlaceHolder2_EditableItems.Controls.Add(rowStart); // <tr>

for (int i = 0; i < columnNames.Count; i++) {

lastcount++;

Label infoLabel = new Label();

infoLabel.Text = "test1";
TextBox myValTextBox = new TextBox();

myValTextBox.Text = "test2"

PlaceHolder2_EditableItems.Controls.Add(jumpColumn Start); // <td>

PlaceHolder2_EditableItems.Controls.Add(infoLabel) ;

PlaceHolder2_EditableItems.Controls.Add(jumpColumn Start); // <td>

PlaceHolder2_EditableItems.Controls.Add(myValTextB ox);

if (lastcount == tableColumns)

{

PlaceHolder2_EditableItems.Controls.Add(rowStop); // </tr>

PlaceHolder2_EditableItems.Controls.Add(rowStart); // <tr>

lastcount = 0;

}
}

PlaceHolder2_EditableItems.Controls.Add(tableStop) ;


Apr 6 '07 #2

P: n/a
you need to nest properly. add the tr's to the table controls
collection, td'd to the tr's controls collection, etc.

also there is an HtmlTable controlthat you can use instead.

-- bruce (sqlwork.com)

_MC_ wrote:
Hi,

i want to structure two elements (each conists of 1 Label and 1 Textbox) in
an Table. As I use an Content Place Holder, i thought it is possible to add
the table via Controls.add(Literal). Literal consists of standard html code
like <table>, <tr>, etc.. Nevertheless Asp Net generates me now table in
html code, maybe you see my mistake in the code below. Thanks a lot!

_MC_

Literal tableStart = new Literal(); tableStart.Text =
"<table>";

Literal tableStop = new Literal(); tableStop.Text =
"</table>";

Literal rowStart = new Literal(); rowStart.Text = "<tr>";

Literal rowStop = new Literal(); rowStart.Text = "</tr>";

Literal jumpColumnStart = new Literal(); jumpColumnStart.Text = "<td>";


PlaceHolder2_EditableItems.Controls.Add(tableStart ); // <table>

PlaceHolder2_EditableItems.Controls.Add(rowStart); // <tr>

for (int i = 0; i < columnNames.Count; i++) {

lastcount++;

Label infoLabel = new Label();

infoLabel.Text = "test1";
TextBox myValTextBox = new TextBox();

myValTextBox.Text = "test2"

PlaceHolder2_EditableItems.Controls.Add(jumpColumn Start); // <td>

PlaceHolder2_EditableItems.Controls.Add(infoLabel) ;

PlaceHolder2_EditableItems.Controls.Add(jumpColumn Start); // <td>

PlaceHolder2_EditableItems.Controls.Add(myValTextB ox);

if (lastcount == tableColumns)

{

PlaceHolder2_EditableItems.Controls.Add(rowStop); // </tr>

PlaceHolder2_EditableItems.Controls.Add(rowStart); // <tr>

lastcount = 0;

}
}

PlaceHolder2_EditableItems.Controls.Add(tableStop) ;

Apr 6 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.