How to access build html table to server side?

Asked By 80 points N/A Posted on -
qa-featured

I would like to ask how can I access build html table to server side? Presently I am trying inner html, but that was not accessed to it.

Please help!

SHARE
Answered By 5 points N/A #156592

How to access build html table to server side?

qa-featured

 

Hi

You want to access html table to server side. First which technology do you use? Actually I know ASP.NET and C#. So i am doing answer by using this Technology. If you are use other technology then you can understand basic logic behind it and use it in your technology.

Code:

First of all you have to add runat="server" because you are fetching data from server.
In case you are accessing inner html table. Then you can access rows then cells and then for each cell you can access innerHtml Property. 

Use the following code to create a table on server side:

Table table=new Table(); 
TableRow row=new TableRow(); 
TableCell cell=new TableCell(); 
cell.Text="your TD value Here"; 
row.cells.Add(cell); 
table.rows.Add(row); 
Form1.Control.Add(table);

Include this namespace: using System.Web.UI.HtmlControls;

Use the following code to access data from server:

 

protected void Page_Load(object sender, EventArgs e)
{
            var str= tbl1.Rows[0].Cells[2].InnerHtml;
             lbl1.Text = str.ToString();
}

protected void Page_Load(object sender, EventArgs e)
{
           string str;
           for (int i = 0; i < tbl1.Rows.Count; i++)
        {
            for (int j = 0; j < tbl1.Rows.Cells.Count; j++)
            {
                str = tbl1.Rows.Cells[j].InnerHtml;
                lbl1.Text = lbl1.Text + " " + str;
            }
        }
    }

Related Questions