HOME > .NET Framework > ASP.NET GridView and Checkbox Select All Row Using jQuery
ASP.NET GridView and Checkbox Select All Row Using jQuery
ASP.NET GridView and Checkbox Select All Row Using jQuery ทำปุ่ม Check All /Un Check All เลือกทั้งหมด และไม่เลือกทั้งหมด บทความ ASP.NET การใช้งาน jQuery เพื่อเลือกแถว CheckboxCheck All ใน GridView เลือกแถวทั้งหมด หรือไม่เลือกทั้งหมด โดยใช้ jQuery ในการอ้างถึง Selectors Checkbox ใน GridView
Imports System.Data
Imports System.Data.OleDb
Partial Class _Default
Inherits System.Web.UI.Page
Dim objConn As OleDbConnection
Dim objCmd As OleDbCommand
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim strConnString As String
strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
Server.MapPath("~/App_Data/mydatabase.mdb") & ";"
objConn = New OleDbConnection(strConnString)
objConn.Open()
If Not Page.IsPostBack() Then
BindData()
End If
End Sub
Protected Sub BindData()
Dim strSQL As String
strSQL = "SELECT * FROM customer"
Dim dtReader As OleDbDataReader
objCmd = New OleDbCommand(strSQL, objConn)
dtReader = objCmd.ExecuteReader()
'*** BindData to GridView ***'
myGridView.DataSource = dtReader
myGridView.DataBind()
dtReader.Close()
dtReader = Nothing
End Sub
Protected Sub myGridView_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles myGridView.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
'*** CustomerID ***'
Dim lblCustomerID As Label = CType(e.Row.FindControl("lblCustomerID"), Label)
If Not IsNothing(lblCustomerID) Then
lblCustomerID.Text = e.Row.DataItem("CustomerID")
End If
'*** Name ***'
Dim lblName As Label = CType(e.Row.FindControl("lblName"), Label)
If Not IsNothing(lblName) Then
lblName.Text = e.Row.DataItem("Name")
End If
'*** Email ***'
Dim lblEmail As Label = CType(e.Row.FindControl("lblEmail"), Label)
If Not IsNothing(lblEmail) Then
lblEmail.Text = e.Row.DataItem("Email")
End If
'*** CountryCode ***'
Dim lblCountryCode As Label = CType(e.Row.FindControl("lblCountryCode"), Label)
If Not IsNothing(lblCountryCode) Then
lblCountryCode.Text = e.Row.DataItem("CountryCode")
End If
'*** Budget ***'
Dim lblBudget As Label = CType(e.Row.FindControl("lblBudget"), Label)
If Not IsNothing(lblBudget) Then
lblBudget.Text = FormatNumber(e.Row.DataItem("Budget"), 2)
End If
'*** Used ***'
Dim lblUsed As Label = CType(e.Row.FindControl("lblUsed"), Label)
If Not IsNothing(lblUsed) Then
lblUsed.Text = FormatNumber(e.Row.DataItem("Used"), 2)
End If
End If
End Sub
Protected Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Unload
objConn.Close()
objConn = Nothing
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim CheckID As CheckBox
Dim lblCustomerID As Label
Dim i As Integer
Label1.Text = ""
For i = 0 To myGridView.Rows.Count - 1
CheckID = myGridView.Rows(i).FindControl("CheckID")
lblCustomerID = myGridView.Rows(i).FindControl("lblCustomerID")
If CheckID.Checked = True Then
'*** Have lblID.Text ***'
Me.Label1.Text = Me.Label1.Text & "<br>" & lblCustomerID.Text
End If
Next
End Sub
End Class