Hi i am trying to get gried view data from data base numericaly onfter another. For example first 5 data then another five (6 to 10) then again. I am trying this by clicking on link button but page can not be refresh..i get id from session in manual data source of gried view.
'vb code..
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Me.IsPostBack = False Then
            id = 5
        End If
        Session.Add("gid", " " & id & " ")
    End Sub

    Protected Sub LinkButton3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton3.Click
        MsgBox(" link 2 is clicked")

        id = Integer.Parse(Session.Item("gid").ToString()) + 5

    End Sub

' this is data source query
<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                    ConnectionString="<%$ ConnectionStrings:MBHConnectionString %>" 

                    SelectCommand="SELECT * FROM [Softwares] WHERE ([Soft_id] &lt;= @Soft_id and [Soft_id] &gt;= @Soft_id-5) ORDER BY [Soft_id]">
                    <SelectParameters>
                        <asp:SessionParameter DefaultValue="1" Name="Soft_id" SessionField="gid" 
                            Type="Int32" />
                    </SelectParameters>
    </asp:SqlDataSource>

Dani AI

Generated

— the easiest fix is to either use GridView’s built‑in paging (what hinted at) or, if you want “manual next 5” buttons, update a numeric session/ViewState value and then rebind the grid. The current symptoms come from three common mistakes: storing the session value as a spaced string (the SqlDataSource expects Int32), changing a local id but not persisting it back to Session/ViewState, and not calling DataBind after you change the parameter.

Concrete suggestions you can apply immediately:

  • Prefer GridView paging for simple page‑by‑page navigation: set AllowPaging = True, PageSize = 5 and handle PageIndexChanging to set GridView.PageIndex = e.NewPageIndex and call DataBind().

  • If you want manual “load next 5” links, store a plain integer in Session (no extra spaces), compute min/max in code, set SqlDataSource parameters programmatically, then call GridView.DataBind() so the updated parameter is used.

Example patterns (VB) — not copies of the original code but the minimal logic to use:

' next button
Dim cur As Integer = If(Session("gid") IsNot Nothing, CInt(Session("gid")), 5)
cur += 5
Session("gid") = cur
GridView1.DataBind()
' page index changing
Protected Sub GridView1_PageIndexChanging(sender, e As GridViewPageEventArgs)
    GridView1.PageIndex = e.NewPageIndex
    GridView1.DataBind()
End Sub

If you keep the SqlDataSource approach, change the query to use two parameters (e.g. @Min and @Max or BETWEEN) and set those parameters from code instead of relying on an expression like @Soft_id-5. Also avoid MsgBox on the server — use client script or a debugger to inspect values. Quick checklist: confirm Session("gid") is an integer, update the session value on each click, and always call DataBind() after changing parameters.

Try using GridPageIndexing Event

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.