Why isn’t my data displaying in the next page of Gridview?

50 pts.
Tags:
ASPX
GridView
Microsoft Visual Studio
SQL data
VBScript
Visual Studio 2005
I added a sqldatasource from my toolbox to my aspx page. I then configured the sqldatasource to connect to a table. I then added a gridview to the same aspx page and selected the sqldatasource as it's data source. In addition to other column formatting etc., I set paging to true. I then opened the page in my browser, clicked the button I have on the page to display the gridview's data. However, when I click page 2 the gridview dissapears. I then tried another approach, I added the table directly from the Server Explorer, configured the defaulted SQLDataSource connection, I set paging to true. I then opened the page in my browser, clicked the button I have on the page to display the gridview's data(see new code snippet). However, when I click page 2 the gridview dissapears. That is the problem I'm having. The gridview keeps disappearing when I click a page number. There’s definitely more data to see. I'm sure there's a solution. I thought I just set the paging to true. But obviously it's not that simple. (see code snippet below). Thanks for anyone's suppout. BUTTON CODE: Protected Sub btn_All_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_All.Click Dim objConn As Data.SqlClient.SqlConnection Dim objComm As Data.SqlClient.SqlCommand objConn = New SqlClient.SqlConnection objConn.ConnectionString = "Data Source=CODA2K;Persist Security Info=True;password=codaprod; USER ID=codaprod;Initial Catalog=CODAPROD;" objConn.Open() objComm = New SqlCommand("pr_HolidaySales", objConn) objComm.CommandType = CommandType.StoredProcedure objComm.CommandTimeout = 500 objComm.ExecuteNonQuery() GVHoliday.DataBind() GVHoliday.Visible = True End Sub Open in New Window Select All

Answer Wiki

Thanks. We'll let you know when a new response is added.

clicking the “next page” button does a postback to the server. when the server responds with the page, all the logic for connecting the grid to the datasource and showing the grid is in your button click handler. this means you have to click the button to see the grid again (next page). I would think you may want to put this in a handler for a different event…like Page_LoadComplete.
lol u got it wrong..
u have to have

Protected Sub Grid13_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles Grid13.PageIndexChanging
        Grid13.PageSize = 10
        Grid13.PageIndex = e.NewPageIndex
        Bind()
    End Sub

did your grid bind with correct?
<pre>
GVHoliday.DataSource = datasets
GVHoliday.DataBind()
</pre>
each time page changing or any event occur to gridview..
u need to bind the data to it
and the most important code line is as above..
if u find this solution solve..
how about try to create an external button control for gridview page changing?
just email me the answer with title “external button control for gridview page changing”:
mattrr85@yahoo.com

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following