<%@ Register TagPrefix="Title" TagName="TitleShow" Src="/aspnetdata/Title.ascx" %>
<%@ Import Namespace="System.Data" %>
<html>
  <script language="C#" runat=server>
	void Page_Load(object sender, EventArgs e){
		if(IsPostBack==false){
			bindNew(true);
			}
	}
	void bindNew(Boolean tag){
		if(tag==true){
			DataColumn newDataColumn;  //声明列变量
			DataTable UserDataTable;   //声明数据表变量
			UserDataTable = new DataTable("AllSessions");
			newDataColumn = new DataColumn(); //建立第一个列
			newDataColumn.DataType = System.Type.GetType("System.String");
			newDataColumn.ColumnName = "SessionName";
			UserDataTable.Columns.Add(newDataColumn);//将列加入至数据表
			newDataColumn = new DataColumn(); //建立第二个列
			newDataColumn.DataType = System.Type.GetType("System.String");
			newDataColumn.ColumnName = "SessionType";
			UserDataTable.Columns.Add(newDataColumn); //将列加入至数据表
			newDataColumn = new DataColumn(); //建立第三个列
			newDataColumn.DataType = System.Type.GetType("System.String");
			newDataColumn.ColumnName = "SessionValue";
			UserDataTable.Columns.Add(newDataColumn); //将列加入至数据表
			DataSet DS = new DataSet(); //声明新DataSet
			DS.Tables.Add(UserDataTable); //将数据表加入至DataSet
			Session["NowSession"]=DS;
			DataRow Row;
			for(int i=0;i<=Session.Count-1;i++){
				Row = DS.Tables["AllSessions"].NewRow();
				Row["SessionName"]=Session.Keys[i].ToString();//取得名称
				Row["SessionType"]=Session[i].GetType().ToString();//取得类型
				Row["SessionValue"]=Session[i].ToString();//取得其值
				DS.Tables["AllSessions"].Rows.Add(Row);
			}
			Sessions.DataSource=DS.Tables["AllSessions"].DefaultView;
			Sessions.DataBind();
		}
		else{
			DataSet DS = (DataSet)Session["NowSession"];
			Sessions.DataSource=DS.Tables["AllSessions"].DefaultView;
			Sessions.DataBind();
		}
	}
	void Clear_Click(object sender, EventArgs e){
		Session.RemoveAll();//删除所有Sesion
		bindNew(true);
	}
	void ClearS_Click(object sender, EventArgs e){
		for(int i=0;i<Sessions.Items.Count;i++){
			CheckBox h;
			h=(CheckBox)Sessions.Items[i].Cells[0].Controls[1];
			if(h.Checked == true){ //取得已选取的主键
				Session.RemoveAt(i);
			}
		}
		bindNew(true);
	}
  </script>
<body background="/aspnetdata/images/winback.gif">
<Title:TitleShow id="BookT" Runat="server" />
    <form runat="server">
<asp:button id="b1" Text="ClearAll" OnClick="Clear_Click" Runat="server" />
<asp:button id="b2" Text="ClearSelected" OnClick="ClearS_Click" Runat="server" />
<asp:label id="rr" runat="server" />
      <ASP:DataGrid id="Sessions" runat="server"
        BorderColor="black"
        BorderWidth="1"
        GridLines="Both"
        CellPadding="3"
        CellSpacing="0"
        Font-Name="Verdana"
        Font-Size="10pt"
	DataKeyField="SessionName"
	AutoGenerateColumns="FALSE"
        HeaderStyle-BackColor="LightYellow"
	HeaderStyle-HorizontalAlign="Center"
	SelectedItemStyle-BackColor="#FFFFC0"
>
       <Columns>
<asp:TemplateColumn HeaderText="Delete" ItemStyle-HorizontalAlign="Center">
          <ItemTemplate>
		<asp:CheckBox runat="server" ID="del" />
          </ItemTemplate>
	</asp:TemplateColumn>
	<asp:BoundColumn HeaderText="SessionName" DataField="SessionName" ItemStyle-Wrap="false"/>
	<asp:BoundColumn HeaderText="SessionType" DataField="SessionType"/>
	<asp:BoundColumn HeaderText="SessionValue" DataField="SessionValue"/>
	</Columns>
</ASP:DataGrid>
</Form>