<%@ Register TagPrefix="Title" TagName="TitleShow" Src="/aspnetdata/Title.ascx" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Web" %>
<html>
<head>
	<script language="VB" runat="server">
	Dim Source as SqlConnection
	Dim d as string="SELECT * FROM Employees"
	sub Page_load(sender as object,e as EventArgs)
		Source = Ctype(Session("NowSTKSQL"),SqlConnection)
		if IsPostBack=false then
			bindNew(true)
		end if
	end sub
	sub bindNew(tag as Boolean)
		if tag=true then
			Dim DS as DataSet = new DataSet()
			Dim NComm as SqlDataAdapter = new SqlDataAdapter(d, Source)
			NComm.Fill(DS, "Employees")
			Dim newCol as DataColumn = new DataColumn()'声明新列
			newCol.DataType = System.Type.GetType("System.Int32")
			newCol.ColumnName = "Send"
			DS.Tables("Employees").Columns.Add(newCol)'加入新列
			AllEmp.DataSource=DS.Tables("Employees").DefaultView
			AllEmp.DataBind()
			Session("DBEmail")=DS'声明为Session
		end if
	end sub
	sub next_click(sender as object,e as EventArgs)
		Dim DS as DataSet = Ctype(Session("DBEmail"),DataSet)
		Dim i as Integer = 0
		for i=0 to AllEmp.Items.Count-1
			Dim k as CheckBox = Ctype(AllEmp.Items(i).Cells(0).Controls(1),CheckBox)
			if k.Checked=true then'检查复选框的值
				DS.Tables("Employees").Rows(i)("Send")=-1
			else
				DS.Tables("Employees").Rows(i)("Send")=0
			end if
			DS.Tables("Employees").AcceptChanges()'保存更改
		next
		Response.Redirect("SendMail.aspx")'切换至另一网页
	end sub
	</script>
</head>
<body background="/aspnetdata/images/winback.gif">
<Title:TitleShow id="BookT" Runat="server" />
<form runat="server">
     <ASP:DataGrid id="AllEmp" runat="server"
        BorderColor="black"
        BorderWidth="1"
        GridLines="Both"
        CellPadding="3"
        CellSpacing="0"
        Font-Name="Verdana"
        Font-Size="8pt"
        HeaderStyle-BackColor="Yellow"
DataKeyField="EmID"
AutoGenerateColumns="false"
>
      <Columns>
<asp:TemplateColumn HeaderText="发送" ItemStyle-HorizontalAlign="right">
          <ItemTemplate>
<asp:CheckBox runat="server" Selected='<%# DataBinder.Eval(Container.DataItem, "Send") %>' ID="Deli" />
          </ItemTemplate>
        </asp:TemplateColumn>
        <asp:BoundColumn HeaderText="人员编号" ReadOnly="True" DataField="EmID" ItemStyle-Wrap="false"/>
        <asp:BoundColumn HeaderText="姓名" DataField="Cname"/>
        <asp:BoundColumn HeaderText="电子邮件" DataField="Email" ItemStyle-HorizontalAlign="right"/>
      </Columns>
</ASP:DataGrid>
<p><asp:Button Text="下一步" id="next" Onclick="next_click" Runat="server" />
</form>
</body>