Find Control in Datagrid

Discussion in 'ASP .Net Datagrid Control' started by Jack, Apr 11, 2005.

  1. Jack

    Jack Guest

    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
    Jack, Apr 11, 2005
    #1
    1. Advertising

  2. Jack

    Elton Wang Guest

    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



    >-----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
    >.
    >
    Elton Wang, Apr 11, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. trinitypete

    DataGrid OnItemBound find control

    trinitypete, Aug 1, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    930
    trinitypete
    Aug 1, 2003
  2. Cheng
    Replies:
    2
    Views:
    9,347
    dany7487
    Nov 14, 2007
  3. Wybo Dekker
    Replies:
    1
    Views:
    351
    Yukihiro Matsumoto
    Nov 15, 2005
  4. vdvorkin
    Replies:
    0
    Views:
    398
    vdvorkin
    Feb 10, 2011
  5. vdvorkin
    Replies:
    3
    Views:
    806
    vdvorkin
    Feb 14, 2011
Loading...

Share This Page