Ahmad Shaheen
Ahmad Shaheen

Reputation: 3

Convert HTML table code to asp:table control

I have an HTML table code (starts with <table> and ends with </table>), how can I make my asp web page to add this table programmatically?

Upvotes: 0

Views: 1863

Answers (3)

Arindam Nayak
Arindam Nayak

Reputation: 7462

If you have purely HTML code generated in server side, then you can add that HTML code having <Table> into your asp page like this.

  1. Add a placeholder to aspx page like this.

<asp:PlaceHolder ID="plc" runat="server" />

  1. In page_load event write this.

    String str = "<table><tr><td>TD VALUE</td></tr></table>";

    plc.Controls.Add(new LiteralControl(str));

This will emit html code , and place them to placeholder.

ASSUMPTION This is just a readonly html code , that you wan to show in page, you are not intended to get those value in server side code on post back. Nor there is any editable field inside the generated table.

Upvotes: 1

Pleun
Pleun

Reputation: 8920

Either redo it in asp:table as you already mentioned or add runat="server" to your existing table and you will be able to alter it in codebehind.

After runat = server you can do things like

protected void Page_Load(object sender, EventArgs e)

    {

       var str= tbl1.Rows[0].Cells[2].InnerHtml;



    }

But I would probably redo it in <asp:table> if you are using webforms. See full example here Add rows to a table dynamically

Upvotes: 0

ZAZ
ZAZ

Reputation: 593

if you want to access this table programatically then use

<table runat="server" id="YOUR_ID"></TABLE>  

it will then let you access this control through asp.net

Upvotes: 0

Related Questions