GridView Buttons not Working?

In my experience, the most common reason for Buttons in a GridView not working is that data is being bound to the GridView during the postback.

In other words, the code looks something like this:

[sourcecode language="VB"]
Protected Sub Page_Load(ByVal sender As Object, _
    ByVal e As System.EventArgs) Handles Me.Load

    Me.gvMyGridView.DataSource=getData()
    Me.gvMyGridView.DataBind()

End Sub
[/sourcecode]

When it should look like this:

[sourcecode language="VB"]
Protected Sub Page_Load(ByVal sender As Object, _
    ByVal e As System.EventArgs) Handles Me.Load

    If Not IsPostBack Then
        Me.gvMyGridView.DataSource=getData()
        Me.gvMyGridView.DataBind()
    End If

End Sub
[/sourcecode]
Be Sociable, Share!
This entry was posted in ASP.Net, VB.Net. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *