Groups | Blog | Home
all groups > asp.net > april 2005 >

asp.net : Finding a Control in a Datagrid


jack-b NO[at]SPAM humlog.com
4/10/2005 10:18:58 PM
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,
Steven Berkovitz
4/11/2005 12:00:00 AM
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.


[quoted text, click to view]

AddThis Social Bookmark Button