<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm2.aspx.vb" Inherits="WebApplication1grid.WebForm2"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm2</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
<script language="javascript">
function SelectAll()
{
var e = event.srcElement;
var inputs = document.forms[0].elements;
for (var i=0; i < inputs.length; i++)
if (inputs[i].type == "checkbox" && inputs[i].name.indexOf("chkMyDataGrid") >=0)
inputs[i].checked = e.checked;
}
</script>
</HEAD>
<body>
<form id="Form1" runat="server">
<h3> </h3>
<asp:datagrid id="MyDataGrid" runat="server" AutoGenerateColumns="False" AllowPaging="True" OnPageIndexChanged="ChangePage"
PageSize="5">
<Columns>
<asp:BoundColumn DataField="姓名" ReadOnly="True" HeaderText="姓名"></asp:BoundColumn>
<asp:BoundColumn DataField="学号" ReadOnly="True" HeaderText="学号"></asp:BoundColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:CheckBox id="chkMyDataGrid" runat="server" Text="Test" />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
<PagerStyle NextPageText="上一页" PrevPageText="下一页"></PagerStyle>
</asp:datagrid>
<P><asp:checkbox id="mycheck" onclick="SelectAll()" runat="server" Text="Check/Uncheck all"></asp:checkbox><asp:button id="btn" runat="Server" text="submit"></asp:button></P>
<P>当前页是:<font color="red"><%=myDataGrid.CurrentPageIndex+1%></font>总页数是:<font color="red"><%=myDataGrid.PageCount%></font></P>
</form>
</body>
</HTML>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm2</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
<script language="javascript">
function SelectAll()
{
var e = event.srcElement;
var inputs = document.forms[0].elements;
for (var i=0; i < inputs.length; i++)
if (inputs[i].type == "checkbox" && inputs[i].name.indexOf("chkMyDataGrid") >=0)
inputs[i].checked = e.checked;
}
</script>
</HEAD>
<body>
<form id="Form1" runat="server">
<h3> </h3>
<asp:datagrid id="MyDataGrid" runat="server" AutoGenerateColumns="False" AllowPaging="True" OnPageIndexChanged="ChangePage"
PageSize="5">
<Columns>
<asp:BoundColumn DataField="姓名" ReadOnly="True" HeaderText="姓名"></asp:BoundColumn>
<asp:BoundColumn DataField="学号" ReadOnly="True" HeaderText="学号"></asp:BoundColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:CheckBox id="chkMyDataGrid" runat="server" Text="Test" />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
<PagerStyle NextPageText="上一页" PrevPageText="下一页"></PagerStyle>
</asp:datagrid>
<P><asp:checkbox id="mycheck" onclick="SelectAll()" runat="server" Text="Check/Uncheck all"></asp:checkbox><asp:button id="btn" runat="Server" text="submit"></asp:button></P>
<P>当前页是:<font color="red"><%=myDataGrid.CurrentPageIndex+1%></font>总页数是:<font color="red"><%=myDataGrid.PageCount%></font></P>
</form>
</body>
</HTML>
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
If Not IsPostBack Then
OpenDataBase_And_BindToDataGrid()
End If
End Sub
Private Sub btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn.Click
Dim dgi As DataGridItem
For Each dgi In MyDataGrid.Items
Dim cb As CheckBox = CType(dgi.FindControl("chkMyDataGrid"), CheckBox)
If cb.Checked Then
Response.Write(("deleting " + dgi.Cells(1).Text + "<BR>"))
End If
Next dgi
End Sub
Sub ChangePage(ByVal sender As Object, ByVal e As DataGridPageChangedEventArgs)
MyDataGrid.CurrentPageIndex = e.NewPageIndex
OpenDataBase_And_BindToDataGrid()
End Sub
Sub OpenDataBase_And_BindToDataGrid()
Dim Conn As OleDbConnection
Dim Adpt As OleDbDataAdapter
Dim Ds As DataSet
Dim Provider = "Provider=Microsoft.Jet.OLEDB.4.0"
Dim Database = "Data Source=" & Server.MapPath("Sample.mdb")
Conn = New OleDbConnection(Provider & ";" & Database)
Conn.Open()
Dim SQL = "Select * From 成绩单"
Adpt = New OleDbDataAdapter(SQL, Conn)
Ds = New DataSet
Adpt.Fill(Ds, "成绩单")
MyDataGrid.DataSource = Ds.Tables("成绩单").DefaultView
Dim bbbb = Ds.Tables("成绩单").DefaultView.Count '总条数
MyDataGrid.DataBind()
Conn.Close()
End Sub
'在此处放置初始化页的用户代码
If Not IsPostBack Then
OpenDataBase_And_BindToDataGrid()
End If
End Sub
Private Sub btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn.Click
Dim dgi As DataGridItem
For Each dgi In MyDataGrid.Items
Dim cb As CheckBox = CType(dgi.FindControl("chkMyDataGrid"), CheckBox)
If cb.Checked Then
Response.Write(("deleting " + dgi.Cells(1).Text + "<BR>"))
End If
Next dgi
End Sub
Sub ChangePage(ByVal sender As Object, ByVal e As DataGridPageChangedEventArgs)
MyDataGrid.CurrentPageIndex = e.NewPageIndex
OpenDataBase_And_BindToDataGrid()
End Sub
Sub OpenDataBase_And_BindToDataGrid()
Dim Conn As OleDbConnection
Dim Adpt As OleDbDataAdapter
Dim Ds As DataSet
Dim Provider = "Provider=Microsoft.Jet.OLEDB.4.0"
Dim Database = "Data Source=" & Server.MapPath("Sample.mdb")
Conn = New OleDbConnection(Provider & ";" & Database)
Conn.Open()
Dim SQL = "Select * From 成绩单"
Adpt = New OleDbDataAdapter(SQL, Conn)
Ds = New DataSet
Adpt.Fill(Ds, "成绩单")
MyDataGrid.DataSource = Ds.Tables("成绩单").DefaultView
Dim bbbb = Ds.Tables("成绩单").DefaultView.Count '总条数
MyDataGrid.DataBind()
Conn.Close()
End Sub