สอบถามการค้นหา ASP.net กับ Gridview เวลาพิมพ์ตรง Textbox ด้านบนแล้วให้ค้นหาและแสดงออกมาใน Gridview
ปกติ VB.net ใช้ Event KeyDown แต่ใน ASP.net มันไม่มี ต้องทำยังไงคับ
Code (VB.NET)
Imports System.Data
Imports System.Data.SqlClient
Imports System.Globalization
Partial Class Details
Inherits System.Web.UI.Page
Dim day2 As Date = DateTime.Today
Dim cn As SqlConnection
Dim da As SqlDataAdapter
Dim dt As DataTable
Dim com As SqlCommand
Dim dvs As DataView
Dim sql As String = ""
Sub ShowData1()
sql = "SELECT dbo.BCITEM.Code, dbo.BCITEM.CategoryCode, dbo.BCITEM.Name1, dbo.BCITEM.GroupCode, dbo.BCItemUnit.Name, dbo.BCITEM.AccGroupCode"
sql &= " FROM dbo.BCITEM INNER JOIN"
sql &= " dbo.BCItemUnit ON dbo.BCITEM.DefStkUnitCode = dbo.BCItemUnit.Code"
da = New SqlDataAdapter(sql, cn)
dt = New DataTable
da.Fill(dt)
If dt.Rows.Count > 0 Then
GV1.DataSource = dt
GV1.DataBind()
End If
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
cn = New SqlConnection
With cn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = "Server=server2005;UID=sa;PASSWORD=nin105;database=csw58;Max Pool Size=400;Connect Timeout=600;"
.Open()
End With
Me.ShowData1()
End Sub
Protected Sub TextBox1_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Disposed
dvs = dt.DefaultView
dvs.RowFilter = "Code Like '%" & TextBox1.Text & "%'or Name1 LIKE '%" & TextBox1.Text & "%'"
GV1.DataSource = dvs
GV1.DataBind()
End Sub
End Class
Tag : .NET, Ms SQL Server 2005, Web (ASP.NET), VB.NET