Finding a Control in a Datagrid

  • Thread starter Thread starter Jack
  • Start date Start date
J

Jack

Hi,

I have a datagrid and I'm wanting to access one of the hyperlinks
which is located in Template Column i.e.

<asp:TemplateColumn HeaderText="Action">
<HeaderStyle Width="100px"></HeaderStyle>
<ItemTemplate>

<asp:hyperlink ID="DeleteHyperlink" runat="server"
NavigateUrl="main.aspx">Delete</asp:hyperlink>

</ItemTemplate>
</asp:TemplateColumn>

I need to do this because I want to add some javascript to the
Attributes property ( i.e. DeleteHyperlink.Attributes.Add("OnClick",
"return confirm('Doyou really want todelete?'")

How do I find this control in the ItemDataBound event???

I tried this but it didn't work:
Dim ExpireAncor As HyperLink =
CType(e.Item.FindControl("ExpireAncor"), HyperLink)

Any suggestions would be great.

Cheers,
Jack
 
The control's id is DeleteHyperlink so you need to use
e.Item.FindControl("DeleteHyperlink"). ExpireAncor is the of your variable,
not the instance of the control.
 

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

Back
Top