' VB.NET Code
Dim tr As TableRow
Dim RowCounter As Integer = 0
For Each tr In GridViewID.Rows
Dim cb As CheckBox = GridViewID.Rows(RowCounter).Cells(0).FindControl("CheckBoxID")
If cb IsNot Nothing And cb.Checked = True Then
'Code to pull data from GridViewID and compare to DB
'Code to Update MySQL Database
RowCounter = +1
End If
next
<!--ASP / HTML CODE-->
<asp:GridView ID="GridViewID" runat="server">
<Columns>
<asp:TemplateField HeaderText="CheckBox Column">
<ItemTemplate>
<asp:CheckBox runat="server" ID="CheckBoxID" Checked="false" EnableViewState="true" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
ASKER
ASKER
ASKER
ASKER
ASKER
ASKER
ASKER
ASKER
ASKER
ASKER
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>GridViewWithCheckBoxesTestSite</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField HeaderText="Checked?">
<ItemTemplate>
<asp:CheckBox ID="chkChecked" runat="server" enabled="true" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Date" HeaderText="Date" DataFormatString="{0:d}" HtmlEncode="false" />
<asp:BoundField DataField="Name" HeaderText="Name" HtmlEncode="false" />
</Columns>
</asp:GridView>
</div>
<asp:Button ID="btnDelete" runat="server" Text="Delete and Update" />
</form>
</body>
</html>
Imports MySql.Data.MySqlClient
Imports System.Data.SqlClient
Imports System.IO
Imports System.Data
Partial Class _Default
Inherits System.Web.UI.Page
Dim con As New MySqlConnection
Dim ds As New Data.DataSet
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
GetData()
MsgBox("test")
End Sub
Sub DBConnect()
con.ConnectionString = "data source=server1 ; database=status; uid=root; Password=UndisclosedPassword;"
con.Open()
End Sub
Sub DBClose()
con.Close()
con.Dispose()
End Sub
Sub GetData()
GridView1.DataSource = ""
ds.Clear()
DBConnect()
Dim GetDataDataAdapter As New MySqlDataAdapter("Select Date, Name From transaction", con)
GetDataDataAdapter.Fill(ds, "transaction")
GridView1.DataSource = ds.Tables("transaction")
GridView1.DataBind()
DBClose()
End Sub
Sub CheckForCheckMark()
Dim RowCounter As Integer = 0
Dim tr As GridViewRow
For Each tr In GridView1.Rows
Dim cb As CheckBox = tr.FindControl("chkChecked")
' MsgBox(Convert.ToString(cb.Checked))
If cb.Checked = True Then
MsgBox("Row " & RowCounter & "is checked!")
Else
MsgBox("Row " & RowCounter & "is not checked!")
End If
RowCounter = RowCounter + 1
Next
RowCounter = 0
End Sub
Protected Sub btnDelete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDelete.Click
CheckForCheckMark()
End Sub
End Class
ASKER
The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.
TRUSTED BY