Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Gridview disappears after paging

Status
Not open for further replies.

MzKitty

Programmer
Oct 28, 2003
254
US
Hi. I'm using vs2008 and .Net 3.5 sp.1. This app was working, but now when I page the gridview, I get the webpage, but no gridview. I put a try and catch in my logic but it's not triggering any errors. Here's my code for paging:
Private Sub GridView1_PageIndexChanged(ByVal sender As Object, ByVal e As GridViewPageEventArgs)
Try
GridView1.PageIndex = e.NewPageIndex
GridView1.DataBind()
GridView1.Visible = True
Catch ex As Exception
End Try
' Process_GridView1()
End Sub

This has me stumped. I am using next/previous for paging.
Thanks
Cathy
 
you're swallowing the exception. this is the first problem. remove the try/catch block and see if an exception is thrown. if so, analyze the stacktrace to find where the problem is originating.

as a general rule you should never swallow exceptions. The scenarios for when this is reasonable are few and far between (edge cases).
Code:
Try
   ...do something
Catch ex As Exception
End Try
there are a number of online resources about Exception Management so I won't repeat them here. basically you should use try/finally when you need to clean up resources and try/catch should be used to log, wrap or rethrow.


Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
I removed the try/catch and am not getting any exceptions and I also added the datasource, but the gridview is still not visible when I page. The other controls on the page are visible but not the gridview. I know that there are 52 records in my datasource, so it should have 4 pages (16 lines per page).

Private Sub GridView1_PageIndexChanged(ByVal sender As Object, ByVal e As GridViewPageEventArgs)
GridView1.PageIndex = e.NewPageIndex
GridView1.DataSource = SqlDataSource2
GridView1.DataBind()
GridView1.Visible = True
'Process_GridView1()
End Sub

Cathy
 
Code:
GridView1.DataSource = SqlDataSource2
ouch! are you using datasource controls? if so that's a problem. they cannot be debugged or tested.

also, i thought you needed to set the paging index in the PageIndexChanging event, not pageIndexChanged. finally, set through your code and see what is happening.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
I found my problem. I needed to run thru my page_Load event so the select command would populate the gridview. When I checked the grid for any data, I would get my No Data message and that was why the grid was not visible.

Thank you for all your help.
Cathy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top