Find Controls in a Table

S

Steve P

This is a simple question, but I haven't got it yet.
How can I find the TableCell control within a Table (using FindControl)
Thank you, Steve


Html Code:

<form id="Form1" method="post" runat="server">
<asp:Table>
<asp:TableRow>
<asp:TableCell ID="Cell1">some text</asp:TableCell>
</asp:TableRow>
</asp:Table>
</form>
 
D

Dave Friedel

When you declare the Cell with an ID - you can directly reference the cell
without needing to call a FindControl. If you want to use FindControl, you
could reference the Page.FindControl - and locate the cell or assign an ID
to the table and use the <table>.FindControl to do the same.

regards,
Dave
 
S

Steve P

Thanks, Dave. I was able to figure it out using another method: accessing
the cells of the table by using Table1.Rows[<index>].Cells[index], however,
your second suggestion also works (Table1.FindControl(<cell ID>) and is
probably better because it makes sure that you are accessing the correct cell
in case the position of the cell changes. Accessing the cell directly does
not work for me since only the table, not the cell seem to have visibility;
the following code generates a compile error:

cell1.Text = "new text"
// error is "The type or namespace "cell1" could not be found..."

Thanks,
Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top