Re: Create linkbutton in datagrid_ItemDataBound event, how catch click?

Discussion in 'ASP .Net' started by Teemu Keiski, Jan 2, 2006.

  1. Teemu Keiski

    Teemu Keiski Guest

    Hi,

    you would need to take a bit advanced approach so that control gets
    recreated on postback (just ItemdataBound is not enough, since control is
    not recreated without redatabinding, and that prevents postback event from
    working)

    Here's a post at ASP.NET Forums which should cover all you need to make it
    work

    Dynamically Created Controls in a Datagrid
    http://forums.asp.net/745492/ShowPost.aspx

    After that getting (Link)Button's Click would be either handling ItemCommand
    event in the grid or wiring an event handler method to the control in code
    such as

    AddHandler linkButton.Click, AddressOf linkButton_Click

    where linkButton_Click is a event handler method you need to write for it

    --
    Teemu Keiski
    ASP.NET MVP, AspInsider
    Finland, EU
    http://blogs.aspadvice.com/joteke


    "geronimi" <> wrote in message
    news:...
    >I want to create a linkbutton in a cell because not every row needs one
    > (so I can't setup a linkbuttoncolumn instead of a boundcolumn.)
    >
    > First, i create a linkbutton in the datagrid_ItemDataBound :
    > Dim linkButton As New LinkButton
    > linkButton.Text = name
    > linkButton.CommandName = "PassSelectedClient"
    > linkButton.CommandArgument = id
    >
    > I add it to the controls
    > e.Item.Cells(0).Controls.Add(linkButton)
    >
    > Everything is done well, but I need something to catch the click!
    > I tried to add WithEvents but it can not be done with Dim
    > So i created this as a global: Protected WithEvents linkButton As New
    > KeepIT.WEBGUI.Controls.dcaLinkButton, but then my page is not rendered
    > well (only the last row contains a link :( )
    >
    > How can I make it work with the click?
    >
    Teemu Keiski, Jan 2, 2006
    #1
    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. Robert Warnestam

    Dynamic LinkButton - how to catch the event?

    Robert Warnestam, Aug 9, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    527
    Robert Warnestam
    Aug 9, 2004
  2. =?Utf-8?B?cm9kY2hhcg==?=

    datagrid_ItemDataBound question

    =?Utf-8?B?cm9kY2hhcg==?=, Nov 23, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    430
    =?Utf-8?B?cm9kY2hhcg==?=
    Nov 24, 2004
  3. =?Utf-8?B?cm9kY2hhcg==?=

    DataGrid_ItemDataBound

    =?Utf-8?B?cm9kY2hhcg==?=, Sep 9, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    781
    Nathan Sokalski
    Sep 10, 2005
  4. AZNewsh

    dataGrid_ItemDataBound - System.InvalidCastException

    AZNewsh, Nov 17, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    94
    Scott Mitchell [MVP]
    Nov 18, 2004
  5. Sally
    Replies:
    2
    Views:
    129
    Keith Smith [MSFT]
    Dec 6, 2003
Loading...

Share This Page