How tro use FindControl (C# or VB)

P

Paul

I have an item in the aspx part of my page:

<a id="PreviousPageNav" runat="server" >

<asp:Image runat=server ID="PreviousImage"
ImageUrl="~/Images/Nav/previous.gif" />

</a>

that I put in the header of a DataList.

When it was outside of the Datalist, on the Code Behind, I accessed it like
this:

PreviousPageNav.HRef = String.Format(navigationFormat, StoreID, pageIndex -
1);

PreviousPageNav.Visible = (pageIndex > 0) ? true : false;



But I can not seem to be able to access it once it is in the header of the
DataList. Looking around, I see the FindControl method, but am usure on how
to use it.

Suggestions, please?



Paul
 
N

Nathan Sokalski

I have never needed to modify the Controls in the HeaderTemplate before, but
I think that you would simply do something like:


YourDataListID.FindControl("PreviousPageNav").HRef=String.Format(navigationFormat,
StoreID, pageIndex-1);


The FindControl(ControlID) method returns a reference to the Control with
ControlID, so you can basically use it in place of where you would normally
just use ControlID. But I have never actually tried this with
HeaderTemplates (although I have with the different ItemTemplates, so I
expect it will be the same), so hopefully it will work. Good Luck!
 

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,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top