469,950 Members | 2,338 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,950 developers. It's quick & easy.

Create linkbutton in datagrid_ItemDataBound event, how catch click?

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?

Jan 2 '06 #1
1 2149
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" <we******@hotmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
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?

Jan 2 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Solomon Shaffer | last post: by
10 posts views Thread by Bharat | last post: by
1 post views Thread by Bijoy Naick | last post: by
2 posts views Thread by msnews.microsoft.com | last post: by
1 post views Thread by Jack | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.