I have a gridview on my application that is populated from a recordset after a user selects criteria from a host of drop down lists etc. This is working fine.
However, due to the possible and probable large number of records that will be returned I decided to use paging to make it visually easier to digest.
The problem I'm having is that after the grid loads the records and you attempt to click to another page od records, the whole gridview dissapears. I am obviously missing something important but I just cannot figure out what.
Here is the code for loading the grid: (by the way, I am testing this on a small access database just to get the fundamentals right)
Code:
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()
If GridView1.Rows.Count > 0 Then
lblRowCount.Text = GridView1.Rows.Count
Else : lblRowCount.Text = "No"
End If
con.Close()
End Sub
And here is the event handler for the page index changing
Code:
Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridView1.PageIndexChanging
GridView1.PageIndex = e.NewPageIndex
GridView1.DataBind()
End Sub
Here is the grid view properties in ASP
Code:
<asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333"
GridLines="None" Height="135px" Width="1218px" AllowPaging="True"
PageSize="2" OnPageIndexChanging="GridView1_PageIndexChanging">
<RowStyle BackColor="#EFF3FB" HorizontalAlign="Center" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#2461BF" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>