<%@ 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="C#" runat="server">
	SqlConnection Source;
	string d="SELECT * FROM Employees";
	void Page_load(object sender,EventArgs e){
		Source = (SqlConnection)Session["NowSTKSQL"];
		if(IsPostBack==false){
			bindNew(true);
		}
	}
	void bindNew(Boolean tag){
		if(tag==true){
			DataSet DS = new DataSet();
			SqlDataAdapter NComm = new SqlDataAdapter(d, Source);
			NComm.Fill(DS, "Employees");
			DataColumn newDCol = new DataColumn();//声明新栏
			newDCol.DataType = System.Type.GetType("System.Int32");
			newDCol.ColumnName = "Send";
			DS.Tables["Employees"].Columns.Add(newDCol);//加入新栏
			AllEmp.DataSource=DS.Tables["Employees"].DefaultView;
			AllEmp.DataBind();
			Session["DBEmail"]=DS;//声明为Session
		}
	}
	void next_click(object sender,EventArgs e){
		DataSet DS = (DataSet)Session["DBEmail"];
		for(int i=0;i<=AllEmp.Items.Count-1;i++){
			CheckBox k = (CheckBox)AllEmp.Items[i].Cells[0].Controls[1];
			if(k.Checked==true){//检查复选框的值
				DS.Tables["Employees"].Rows[i]["Send"]=-1;
			}
			else{
				DS.Tables["Employees"].Rows[i]["Send"]=0;
			}
			DS.Tables["Employees"].AcceptChanges();//保存更改
		}
		Response.Redirect("SendMail.aspx");//切换至另一网页
	}
	</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>