By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,925 Members | 725 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,925 IT Pros & Developers. It's quick & easy.

LinkButton inside DataGrid Header

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.