Find Control in Datagrid

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
 
E

Elton Wang

Hi Jack,

Use following code

If e.Item.ItemType = ListItemType.AlternatingItem OrElse _
e.Item.ItemType = ListItemType.Item Then
Dim ExpireAncor As HyperLink = CType(e.Item.FindControl
("DeleteHyperlink"), HyperLink)

' ...

End If

HTH

Elton Wang
(e-mail address removed)
 

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,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top