Programatically access an HTML table control
How do I programatically access an HTML table control from within VB? I actually want to access one of the table headers and set the text dependent on some logic.
I have given the table an ID="tbJobs" and the table header cell an ID="tbCustomField".
Any ideas?
Re: Programatically access an HTML table control
In the CodeBehind...
VB Code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.tbJobs.Rows(0).Cells(0).Text = "My Table Header"
'...
Re: Programatically access an HTML table control
You also have to give the table a runat attribute.
<table id="abc" runat="server"...>
Note, however. Once you make this change in the html view, go to design view, save the page, and THEN go into the codebehind.
Re: Programatically access an HTML table control
Well, here's the rub. When i give it the runat="server" attribute, it complains that it can't convert a repeater control into a table header. This is because I am using an HTML table to format data displayed with a repeater control. It's kind of embedded in my HTML table. And it doesn't like it when I set the table to run at the server...
Re: Programatically access an HTML table control
Ah, you see, that was a bit of important information: The table is part of the template of a repeater control. :)
You need to get the repeater's ItemDataBound event. It's in there that you can check to see, first, the type of the row you are looking at (It could be ListItemType.Header, .Item, .Footer), and then if that condition is met, do a .FindControl() on the EventArg parameter of the event. (e.FindControl("tableid"))
Re: Programatically access an HTML table control
And using the ItemDataBound event...my HTML table does not need to be runat="server"?
Re: Programatically access an HTML table control
No, it doesn't. Because the table will then only exist as part of the control collection of the item/header/footer in your repeater control. It's the same for a datagrid and I can vaguely recall talking to you about a similar situation back when...
Re: Programatically access an HTML table control
Are you accusing me of having a short memory? Why you...you...whatever you name is!