Click here to Skip to main content
15,887,812 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I know this is simple and I must be overlooking something. I'm trying on a button click to bind and display my gridview. I've tried a few variations on the code. Either the page posts back or it does not post back either way a gridview never populates on the button click. If I change the code and have it populate on page load then works fine but once moved to button click nothing appears.

I've tried with and with out the post back.

 Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    If IsPostBack = False Then
        gridview.DataSource = SqlDataSource1
        gridview.DataBind()
    End If

End Sub


thanks
Posted
Comments
Mantu Singh 5-May-15 9:08am    
try removing If IsPostBack = False Then
because when u click button page is posted to server got it!!

1 solution

try this

VB
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        If IsPostBack = True Then
            gridview.DataSource = SqlDataSource1
            gridview.DataBind()
        End If

    End Sub
 
Share this answer
 
Comments
Troy Bryant 5-May-15 9:14am    
Nope neither of these worked. I originally didnt have post back but I've made it true and then deleted same results
Mantu Singh 5-May-15 9:18am    
have you configured sqldatasource properly
Troy Bryant 5-May-15 9:22am    
To my knowledge yes. Its a simple select command nothing fancy
Mantu Singh 5-May-15 9:28am    
my sample code works just fine

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:SKTConnectionString %>"
SelectCommand="SELECT * FROM [CLIENT_DET_SMRY]">
<asp:Button ID="Button1" runat="server" Text="Next" onclick="Button1_Click" />

<asp:GridView ID="GridView1" runat="server" Height="168px" Width="322px">

<asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="Button" />

Select the Sql data source & see its ConnectionString property like
Data Source=sqlserver;Initial Catalog=DB;User ID=sa;Password=password

if not click small arrow top right corner of sqldatasource & Configure datasource...
Troy Bryant 5-May-15 10:16am    
I deleted the grid and ds and just started fresh seemed to have fixed it. I have no idea what happened but thanks for the help

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900