Due to the probably amount of records that will be returd, I decided to allow paging to make the data more visually appealing. So far, so good. Everything is running smoothly until.. you try to selct a new page on the datagrid. The grid just disappears!!!
here is the vb code that populates the datagrid.
Expand|Select|Wrap|Line Numbers
- Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
- con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\Documents and Settings\Chris\Desktop\incidents.mdb"
- con.Open()
- sql = "SELECT * FROM tbl_incidents WHERE Address Like '%" & txtAddress.Text & "%' And Borough Like '%" & ddlborough.SelectedValue & "%'"
- da = New OleDb.OleDbDataAdapter(sql, con)
- da.Fill(ds, "incidents")
- GridView1.DataSource = ds.Tables("incidents")
- GridView1.DataBind()
- con.Close()
- End Sub
Expand|Select|Wrap|Line Numbers
- Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridView1.PageIndexChanging
- GridView1.PageIndex = e.NewPageIndex
- If Page.IsPostBack Then
- GridView1.DataSource = ds.Tables("incidents")
- GridView1.DataBind()
- End If
- End Sub
An odd thing is that I have a clear button on the app which clears any text in textboxes left over from the search and resets the drop down lists to their defaults. On click, the gridview re-appears again on the page you requested when you lost it, however, it has the records from the first page in it still.
I cannot for the life of me solve this issue and I would be forever grateful for a solution.
Thanks