We help IT Professionals succeed at work.
Get Started

Gridview Dynamic LinkButton Control with CommandName Problem

joeylu
joeylu asked
on
1,519 Views
Last Modified: 2013-11-26
the structure is like this:

Grivdivew
    ItemTemplate
        PlaceHolder
    /ItemTemplate
/Gridview

And then I try to add some dynamic controls into the placehold control from code behind, I use the RowDataBound Event

Private Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
            Dim ph As PlaceHolder = CType(e.Row.Cells(1).FindControl("PlaceHolder"), PlaceHolder)
            Dim Button1 As New LinkButton
            Button1 .Text = "1234567"
            Button1 .CommandName = "Select"
            ph.Controls.Add(Button1 )
End Sub

The problem is the button CommandName is not functioning. And more strangely, if I add the button manually into the placeholder, like this:
Grivdivew
    ItemTemplate
        PlaceHolder
            <asp:LinkButton id=button1 runat=server text=123456 commandName=select />
        /PlaceHolder
    /ItemTemplate
/Gridview
This works perfectly.

Any idea?
Comment
Watch Question
Technical Analyst
Commented:
This problem has been solved!
Unlock 1 Answer and 5 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE