473,385 Members | 1,736 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 2295
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Kiyomi | last post by:
Hello, I create a Table1 dynamically at run time, and at the same time, I would like to create LinkButton controls, also dynamically, and insert them into each line in my Table1. I would...
3
by: CodeRazor | last post by:
Hi, I am trying to dynamically create linkbuttons. They need an event handler, so i can respond to the user's click. I try to add the eventhandler on the fly, but when i click on the link, the...
0
by: Solomon Shaffer | last post by:
This is very interesting - and odd. I have a number of LinkButtons that are created in a custom data grid that I created. The purpose of the LinkButtons is to provide alphabetical filtering...
10
by: Bharat | last post by:
Hi Folks, Suppose I have two link button on a page (say lnkBtn1 and lnkBtn2). On the click event of the lnkbtn1 I have to add a dynamically created control. And On the click event of the lnkBtn2 I...
1
by: Bijoy Naick | last post by:
I have 2 datagrids, lets call them src and dest. I run a query and databind to src. Src contains a column called "name". I use a templatecolumn to display the name as a LinkButton. I want the...
1
by: smash2004 | last post by:
I have VS 2005 CTP. I created a page with one repeater. Inside i put a linkbutton. Usually when i put linkbutton on a page I doubleclick it in designview and event gets created in codebehind...
2
by: msnews.microsoft.com | last post by:
I want to read information out of a database at runtime (names of files available to download) and create a list of linkbuttons that the user can click on to download the file(s). How can I...
0
by: OceanBreeze | last post by:
I have added a LinkButton to a table cell programmatically inside the Page_Load method. I also added a custom event to that link button. The same custom event is valid for all the link buttons. The...
1
by: Jack | last post by:
Hi, I am new to .NET and need help with adding click event on LinkButton programatically. Please see the code below. I would like to add a click event on LinkButton returned from "Function...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.