473,406 Members | 2,620 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,406 software developers and data experts.

LinkButton inside DataGrid Header

I add a link button to the header of my datagrid as follows:
If e.Item.ItemType = ListItemType.Header Then
Dim myLink As New LinkButton()
myLink.Text = "Add New"
myLink.Attributes.Add("runat", "server")
myLink.Attributes.Add("id", "btnAddNew")
myLink.Attributes.Add("CommandName", "btnAddNew")
myLink.Attributes.Add("CommandArgument", "btnAddNew")
e.Item.Cells(2).Controls.Add(myLink)
AddHandler myLink.Click, AddressOf Me.btnAddNew_Click
End If
After postback the sub, btnAddNew_Click is not called. I assume this
is because since the control is created programatically, it needs to
be recreated on postback by the page_onload. However, at page_onload
the datagrid is not yet created, so how can I create the LinkButton
and add it?
Thanks!
Nov 17 '05 #1
1 1890
Write the code for creating link button in item_created event of datagrid.

--
Saravana
Microsoft MVP - ASP.NET
www.extremeexperts.com

"Dude" <ho****@post.com> wrote in message
news:1c**************************@posting.google.c om...
I add a link button to the header of my datagrid as follows:
If e.Item.ItemType = ListItemType.Header Then
Dim myLink As New LinkButton()
myLink.Text = "Add New"
myLink.Attributes.Add("runat", "server")
myLink.Attributes.Add("id", "btnAddNew")
myLink.Attributes.Add("CommandName", "btnAddNew")
myLink.Attributes.Add("CommandArgument", "btnAddNew")
e.Item.Cells(2).Controls.Add(myLink)
AddHandler myLink.Click, AddressOf Me.btnAddNew_Click
End If
After postback the sub, btnAddNew_Click is not called. I assume this
is because since the control is created programatically, it needs to
be recreated on postback by the page_onload. However, at page_onload
the datagrid is not yet created, so how can I create the LinkButton
and add it?
Thanks!

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Fresh Air Rider | last post by:
Hi Could anyone please give me the syntax for calling a function with more than one parameter from an <asp:LinkButton> ? Many thanks John
1
by: Rodusa | last post by:
I keep getting this error when trying to modify the text property of a linkbutton inside a datagrid template column. Object reference not set to an instance of an object. Description: An...
0
by: Dude | last post by:
I add a link button to the header of my datagrid as follows: If e.Item.ItemType = ListItemType.Header Then Dim myLink As New LinkButton() myLink.Text = "Add New" myLink.Attributes.Add("runat",...
0
by: Pat Sagaser via .NET 247 | last post by:
I'm trying to add LinkButtons to a Repeater control using adynamic template. The docs state that you should be able tobubble the click event to the containing Repeater. There areplenty of examples in...
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...
4
by: Tim::.. | last post by:
Can someone tell me how I do a response.redirect using a linkbutton in a datagrid! I want to use the record id in a database to send a querystring to an HTML editor so that users are able to...
1
by: Danny Ni | last post by:
Hi, I have a LinkButton inside a datagrid, when this LinkButton is clicked, the program deleete a record in database. I would like to add a confirmation on client side. I know I can do...
5
by: =?Utf-8?B?TWFyYyBXb29sZnNvbg==?= | last post by:
Hi, I have a strange issue occurring with LinkButtons that are dynamically added to each (data) row of my DataGrid on that grid's ItemDataBound event. Each LinkButton is assigned its own event...
5
daJunkCollector
by: daJunkCollector | last post by:
What I am doing here should be obvious. I have a datagrid that displays data properly. I want to create a linkbutton within each row of the datagrid that toggles a label control in the same row...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.