[asp.net]如何用grid實做一個查詢(grid,查詢)

  • 2612
  • 0
  • 2012-06-01

摘要:[asp.net]如何用grid實做一個查詢

先到畫面上拉出一個查詢的按鍵,再拉出一個grid,隨便設定一下,記得把grid放在updatePanel裡面,這樣畫面不會一直閃,比較帥XD

然後在設定一下查詢按鍵code_behind的程式碼,就搞定拉


Protected Sub btnQuery_Click(sender As Object, e As EventArgs) Handles btnQuery.Click
        Dim strSQL As String = ""
        strSQL = " select * from Employees "
        Dim cn As SqlConnection
        Dim da As SqlDataAdapter
        Dim dt As DataTable = New DataTable()
        Try
            cn = New SqlConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings("NorthwindConnectionString").ConnectionString)
            da = New SqlDataAdapter(strSQL, cn)
            da.Fill(dt)

            dtGrid.DataSource = dt
            dtGrid.DataBind()

        Catch ex As Exception

        End Try
    End Sub