Groups | Blog | Home
all groups > asp.net > march 2007 >

asp.net : HT retrieve values in html table from codebehind


Muhammad Naveed Yaseen
3/9/2007 10:17:41 PM
HtmlTableCell cell = table1.Controls[0].Controls[0] as HtmlTableCell;

cell.InnerHtml would evaluate to 'HowToReferenceThisValue'
cell.ID would evaluate to server side id (AAA here)
cell.ClientID would evaluate to client-side id (which may be different
than server side depending on nesting level)

To access some html attribute other than id, use
cell.Attributes["NameOfAttribute"]

Iteration via IEnumerable would be like following (above mentioned
properties can be acessed after casting to HtmlTableRow or
HtmlTableCell if needed)

foreach (Control row in table1.Controls)
{
foreach (Control cell in control.Controls)
{
....
}
}
Muhammad Naveed Yaseen
3/9/2007 10:19:19 PM
HtmlTableCell cell = table1.Controls[0].Controls[0] as HtmlTableCell;

cell.InnerHtml would evaluate to 'HowToReferenceThisValue'
cell.ID would evaluate to server side id (AAA here)
cell.ClientID would evaluate to client-side id (which may be
different
than server side depending on nesting level)


To access some html attribute other than id, use
cell.Attributes["NameOfAttribute"]


Iteration via IEnumerable would be like following (above mentioned
properties can be acessed after casting to HtmlTableRow or
HtmlTableCell if needed)


foreach (Control row in table1.Controls)
{
foreach (Control cell in row.Controls)
{
....
}
}


xzzy
3/9/2007 10:40:06 PM
I have hit a wall with not being able to enumerate the items collection in a
table row.

given:

<table runat=server id=table1>
<tr>
<td id=AAA>HowToReferenceThisValue</td>

etc...

from code behind, how can I iterate thru / parse the html table to get AAA's
text => 'HowToReferenceThisValue'

xzzy
3/10/2007 12:08:30 AM
HtmlTableCell cell = table1.Controls[0].Controls[0] as HtmlTableCell;

cell.InnerHtml would evaluate to 'HowToReferenceThisValue'

++++++++++++++++++++++++++++++++++++++++++++++++++
Problem:
cell.InnerHtml is not a property of cell

further,
table1.Controls[0].Controls[0]
( System.Web.UI.HtmlControls.HtmlTableCell )
only lists the attributes, not the item
++++++++++++++++++++++++++++++++++++++++++++++++++

cell.ID would evaluate to server side id (AAA here)
cell.ClientID would evaluate to client-side id (which may be
different
than server side depending on nesting level)


To access some html attribute other than id, use
cell.Attributes["NameOfAttribute"]

Iteration via IEnumerable would be like following (above mentioned
properties can be acessed after casting to HtmlTableRow or
HtmlTableCell if needed)

++++++++++++++++++++++++++++++++++++++++++++++++++
Problem:
as far as I know, the items collection of
System.Web.UI.HtmlControls.HtmlTableCell is not enumerable
++++++++++++++++++++++++++++++++++++++++++++++++++

foreach (Control row in table1.Controls)
{
foreach (Control cell in row.Controls)
{
....
}
}

Muhammad Naveed Yaseen
3/10/2007 12:28:25 AM
[quoted text, click to view]

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwebuihtmlcontrolshtmlcontainercontrolclassinnerhtmltopic.asp

And HtmlTableCell inherits from HtmlContainerControl.
So yes, InnerHtml is a property of cell (HtmlTableCell to which I had
cast variable 'cell').

[quoted text, click to view]

Attributes is an AttributesCollection
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwebuihtmlcontrolshtmlcontrolclassattributestopic.asp
which implements Item
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwebuiattributecollectionclasstopic.asp
So yes, you can use Item (on Attributes of course).

[quoted text, click to view]

Problem :)
1) HtmlTableCell does not have items collection (as you yourself said
few lines ago).
2) Whichever object has Items, that is enumerable, for the type of
unit of items.
3) I had enumerated Controls collections (not Items), which is, yes,
also enumerable
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwebuicontrolcollectionclasstopic.asp

Why don't you please compile the code first and then comment.
I have compiled it and everything works as expected.
AddThis Social Bookmark Button