0

I have a table in asp.net page and i want to insert the data which will be recieved from service call through c# code behind. Any idea on how to do this.

Below is my table.

<table id="DataTable" class="style1">
    <tr>
        <td>
            &nbsp;</td>
        <td>
            &nbsp;</td>
        <td>
            &nbsp;</td>
        <td>
            &nbsp;</td>
    </tr>
</table>

I just need to insert values recieved from service call in place of &nbsp.

7
  • 3
    What about placing labels there instead of &nbsp? Commented Jan 11, 2012 at 7:20
  • @Scott : Im just trying whether its possible with table Commented Jan 11, 2012 at 7:27
  • 1
    @Chandu- Indyaah OK , yes ! you can. An easy way is add runat = "server" on your table tag. And you can access it in your .cs file. Then , you could insert everything as you like. Commented Jan 11, 2012 at 7:31
  • @Chandu- Indyaah and if you add asp:Label , I donnt know how many td you would have. I think you'd better general it dynamic by your code. Commented Jan 11, 2012 at 7:32
  • 1
    @Chandu- Indyaah Because it's just like 1 sentence. Commented Jan 11, 2012 at 7:47

4 Answers 4

2

In your aspx page asp:Label controls and assign the values from code behind by accessing them using Id.

Inside .aspx

  <asp:Label Id="lblName" runat="server">

In code behind

  lblName.Text = "Value from Service";

If you need to repeat this table use GridView.

Sign up to request clarification or add additional context in comments.

Comments

1

Use the asp:Table control instead.. It gives you much more control from server side than a normal html tag :)

And it ofc render as a normal table client side

Comments

1

If you persist on working with pure html table you can use an new/old style to control it.

like so:

<table>
   <% foreach ( var o in objects ) { %>
    <!--UserControl -->
     <tr>
         <td> can put here data like so: <%= o.Id %> </td>
     </tr>  
     <!--UserControl -->
   <%}%>
</table>

or you can use Repeater and Bind data if it's dynamic.

If data is not dynamic and your table will not grow or change size, you can use a little OOP for this.

like so: create in your class properties and then populate them. public string MyLabel { get; set; }

put something in page load.

in aspx do it like so..

<table>
     <tr>
         <td> <%= MyLabel %> </td>
     </tr>           
</table>

or

    <table>
         <tr>
             <td> <asp:Label ID=|"myText" runat="server"/> </td>
         </tr>           
    </table>

Comments

1

Make the table Html server side control. Try this:

<table runat="server" id="DataTable" class="style1">
<tr>
    <td id="td1" runat="server">
        &nbsp;</td>
    <td id="td2" runat="server">
        &nbsp;</td>
    <td id="td3" runat="server">
        &nbsp;</td>
    <td id="td4" runat="server">
        &nbsp;</td>
</tr>

Now in the code behind

td1.InnerText="xx" or td1.InnerHtml=..

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.