LinkButton inside DataGrid Header

D

Dude

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top