Results 1 to 16 of 16

Thread: [RESOLVED] Gridview Paging

Threaded View

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    617

    Resolved [RESOLVED] Gridview Paging

    I have a web application which does data filtering. The return data set will be bind to Datagridview with Paging set to True.

    vb Code:
    1. Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         Using connection As New SqlConnection("Data Source=localhost\sqlexpress;Initial Catalog=26may;Integrated Security=SSPI;")
    3.             Dim criteria As String = String.Empty
    4.             Dim sql As String = "SELECT pk_ddlvryMasterid,pk_ddlvryno as [Dlvry No],convert(varchar,entereddate,106) as Dated" & _
    5.                     ", lpono as LPO_No, Supplier FROM qDDlvryMaster"
    6.  
    7.             Select Case criteriaDropDownList.Text.ToUpper
    8.                 Case "DLVRY NO" : criteria = "PK_DDLVRYNO"
    9.                 Case "LPO NO" : criteria = "LPONO"
    10.                 Case "SUPPLIER" : criteria = "SUPPLIER"
    11.             End Select
    12.            
    13.             Using command As New SqlCommand(sql & " where " & criteria & " LIKE @value + '%'", connection)
    14.                 command.Parameters.Add("@value", Data.SqlDbType.VarChar).Value = valueTextBox.Text.ToString
    15.  
    16.                 connection.Open()
    17.                 Using reader As SqlDataReader = command.ExecuteReader()
    18.                     Dim tb As New DataTable
    19.                     tb.Load(reader)
    20.                     GridView1.DataSource = tb 'set datasource
    21.                     GridView1.DataBind() 'bind to gridview to view return data set
    22.                 End Using
    23.  
    24.  
    25.             End Using
    26.         End Using
    27.  
    28.     End Sub
    29.  
    30.  
    31.     Protected Sub OnPaging(ByVal sender As Object, ByVal e As GridViewPageEventArgs) Handles GridView1.PageIndexChanging
    32.  
    33.         GridView1.PageIndex = e.NewPageIndex
    34.         GridView1.DataBind()
    35.  
    36.     End Sub

    The code works perfectly but every time I move to different page the gridview clear all the rows.

    And also how can I make the first gridview column create link to its details page?
    Last edited by jlbantang; Jul 17th, 2010 at 03:43 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width