locked
VB.Net GridView Custom Paging Using SqlDataSource Stored Procedure RRS feed

  • Question

  • Can a VB.Net Gridview with SQLDataSource and Stored Procedure implement custom paging?

    The gridview executes the stored procedure correctly, but how do you tell the gridview the count of total records so it can put the 1 2 3 4 5 END so the user can scroll through the pages?


    Developer

    Tuesday, June 17, 2014 9:42 PM

Answers

  • Hello,

    Sounds like an ASP.NET project using Pagination, if so please consider asking your question in the ASP.NET forums. If not, please indicate if the GridView you speak of is perhaps a DataGridView or other container.

    ASP.NET Pagination (article on Code Project)


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.

    Tuesday, June 17, 2014 10:33 PM

All replies

  • Hello,

    Sounds like an ASP.NET project using Pagination, if so please consider asking your question in the ASP.NET forums. If not, please indicate if the GridView you speak of is perhaps a DataGridView or other container.

    ASP.NET Pagination (article on Code Project)


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.

    Tuesday, June 17, 2014 10:33 PM
  • Thank you, I will look at the article link.

    The code below works, but my question is how to I associate the RecordCount variable returned from the stored procedure to the Gridview1 rows count so that the gridview displays the numbers up for the user to page thru.  1 2 3 4 5 6 7 End

    What I have is:

    //vb.net front page

    <asp:GridView ID="GridView1" runat="server" AllowSorting="False" AllowPaging="true" PageSize="50" OnPageIndexChanging="GridView1_PageIndexChanging" >

       <Columns>

          <asp:TemplateField HeaderText="Product Id" >

             <ItemTemplate>

                <asp:Label ID="Product" runat="server" Text='<%# Bind("product") %>'></asp:Label>

             </ItemTemplate>

           </asp:TemplateField>

          <asp:TemplateField HeaderText="Description">

             <Item Template>

             <asp:Label ID="Description" runat="server" Text='<%# Bind("description") %>'></asp:Label>

             </ItemTemplate>

          </asp:TemplateField>

          </Columns>

          <PagerSettings Position="TopAndBottom" Mode="NumericFirstLast" FirstPageText="First &lt;%lt;" LastPageText="Last &gt;%gt;" />

        </asp:GridView>

    // vb.net code behind

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

       If Not IsPostBack Then

          Dim cmd As New SqlCommand("GetFilterPRs", conn)

          cmd.CommandType = CommandType.StoredProcedure

          cmd.Parameters.Add("@CurrentPage", System.Data.SqlDbType.Int)

          cmd.Parameters("@CurrentPage").Value = 1

         cmd.Parameters.Add("@PageSize", System.Data.SqlDbType.Int)

          cmd.Parameters("@PageSize").Value = GridView1.PageSize

          cmd.Parameters.Add("@RecordCount", SqlDbType.Int, 4)

         cmd.Parameters("@RecordCount).Direction = ParameterDirection.Output

          cmd.Connection = conn

          conn.Open()

          reader = cmd.ExecuteReader()

          Dim dt As New DataTable

          dt.Load(reader)

          GridView1.DataSource = dt

          GridView1.DataBind()

          RecordCount = Convert.ToInt32(cmd.Parameters("@RecordCount").Value)

          conn.Close()

       EndIf

    End Sub

    Thank you for your help.


    Developer

    Wednesday, June 18, 2014 3:48 PM