2
<table id="mytable" runat="server"> 
<thead>
    <tr>
        <td >
            </td>
                        <td>
                                    Minute
                                </td>
                                <td 
                                 Category Name
                                </td>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td >
                                    10
                                </td>
                                <td>

                                </td>
                                <td>
                                    <span></span>
                                </td>
                            </tr>
                            <tr >
                                <td>
                                </td>
                                <td>
                                    15
                                </td>
                                <td>
                                    <span></span>
                                </td>
                            </tr>

</table>

This is my html table Here i have to find first cell second cell third cell data of each row in c# How can i find.

Furqan Hameedi
  • 4,372
  • 3
  • 27
  • 34
ND's
  • 2,155
  • 6
  • 38
  • 59

2 Answers2

2

You may try Html agility pack API to parse the html text.

KV Prajapati
  • 93,659
  • 19
  • 148
  • 186
  • I would add to that to apply after parsing an XPath to retrieve only the `TD` elements inside that table. Then it's really easy to iterate through them and extract their inner text. – Marcel N. Jun 30 '12 at 07:35
0

One option is to make the cells into server controls by adding an id and runat=server attributes and then you can access them as htmlcontrols - http://msdn.microsoft.com/en-us/library/system.web.ui.htmlcontrols.htmlcontrol.aspx

You could then use a repeater to generate each row. Then create a method for the ItemDataBound event of the repeater - http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.repeater.itemdatabound.aspx

This allows you to populate the data initially from a suitable data source and if your data source changes, you can simply rebind the source to the repeater to get it to update.

Example of how to find span tag :

<span id="span1" runat="server"></span> 

Add the attributes as above.

Then within the repeater ItemDataBound method

e.Item.FindControl("span1")).innerText= "Hello John";

Note the use of the innerText method to add content within the span tags.

You only need to make the specific elements you need into server controls.

NGRhodes
  • 335
  • 9
  • 19