Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > Find Control in Datagrid

Reply
Thread Tools

Find Control in Datagrid

 
 
Jack
Guest
Posts: n/a
 
      04-11-2005
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
 
Reply With Quote
 
 
 
 
Elton Wang
Guest
Posts: n/a
 
      04-11-2005
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
http://www.velocityreviews.com/forums/(E-Mail Removed)


>-----Original Message-----
>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
>.
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to exclude action of Find::Find::find in subdirectories withknown names? vdvorkin Perl Misc 3 02-14-2011 05:28 AM
How to exclude action of Find::Find::find in subdirectories withknown names? vdvorkin Perl Misc 0 02-10-2011 05:18 PM
how to find control in headertemplate of datagrid Cheng ASP .Net 2 11-14-2007 03:57 PM
Find.find does not find orphaned links? Wybo Dekker Ruby 1 11-15-2005 02:50 PM
DataGrid OnItemBound find control trinitypete ASP .Net 0 08-01-2003 10:59 AM



Advertisments