<%@ Register TagPrefix="Title" TagName="TitleShow" Src="/aspnetdata/Title.ascx" %>
<%@ Import Namespace="System.Data" %>
<html>
  <script language="VB" runat=server>
	sub Page_Load(sender as object,e as EventArgs)
		if IsPostBack=false then
			bindNew(true)
		end if
	end sub
	sub bindNew(tag as Boolean)
		if tag=true then
			Dim newDataColumn as DataColumn '声明列变量
			Dim UserDataTable as DataTable    '声明数据表变量
			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) '将列加入至数据表
			Dim DS as DataSet = new DataSet() '声明新DataSet
			DS.Tables.Add(UserDataTable) '将数据表加入至DataSet
			Session("NowSession")=DS
			Dim Row as DataRow
			Dim i as Integer = 0
			for i=0 to Session.Count-1
				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)
			next
			Sessions.DataSource=DS.Tables("AllSessions").DefaultView
			Sessions.DataBind()
		else
			Dim DS as DataSet = Ctype(Session("NowSession"),DataSet)
			Sessions.DataSource=DS.Tables("AllSessions").DefaultView
			Sessions.DataBind()
		end if
	end sub
	sub Clear_Click(sender as object,e as EventArgs)
		Session.RemoveAll()'删除所有Sesion
		bindNew(true)
	end sub
	sub ClearS_Click(sender as object,e as EventArgs)
		dim i as Integer = 0
		for i=0  to Sessions.Items.Count-1
			dim h as CheckBox
			h=Ctype(Sessions.Items(i).Cells(0).Controls(1),CheckBox)
			if h.Checked = true then '取得已选取之主索引
				Session.RemoveAt(i)
			end if
		next
		bindNew(true)
	end sub
  </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>