<%@ Register TagPrefix="Title" TagName="TitleShow" Src="/aspnetdata/Title.ascx" %>
<%@Page Debug=True %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Web" %>
<%@Import Namespace="System.Threading"%>
<%@Import Namespace="System.Resources"%>
<%@Import Namespace="System.Globalization"%>
<html>
<head>
	<script language="VB" runat="server">
	dim Source as SqlConnection
	dim d as string ="SELECT Staff.*, Category.Content FROM Category INNER JOIN Staff ON Category.ID = Staff.Depart Order by SID"
	sub Page_load(sender as object,e as EventArgs)
		Source = Ctype(Session("NowEmpSQL"),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, "staff")
			Session("NowDS")=DS
			staffShow.DataSource=DS.Tables("staff").DefaultView
			staffShow.DataBind()
		else
			Dim DS as DataSet =Ctype(Session("NowDS"),DataSet)
			staffShow.DataSource=DS.Tables("staff").DefaultView
			staffShow.DataBind()
		end if
	end sub
	sub DeleteSelect(sender as object, e as EventArgs)
		dim SIDString as string=""
		dim DelString as string=""
		dim i as integer=0
		for i=0 to staffShow.Items.Count-1
			dim h as CheckBox
			h=Ctype(staffShow.Items(i).Cells(0).Controls(1),CheckBox)
			if h.Checked = true then
				SIDString +=" or (SID ='" + staffShow.Items(i).Cells(1).Text + "')"
			end if
		next
		if SIDString.Length>0 then
			SIDString=SIDString.Remove(0,4)
			DelString = "Delete from Staff where " + SIDString
			dim DelRec as SqlCommand = new SqlCommand(DelString,Source)
			DelRec.Connection.Open()
			DelRec.ExecuteNonQuery()
			DelRec.Connection.Close()
			bindNew(true)
			errMsg.Text="Delete OK."
		end if
	end sub
	</script>
</head>
<body background="/aspnetdata/images/winback.gif">
<Title:TitleShow id="BookT" Runat="server" />
<form runat="server" id="test">
<asp:button id="delbtn" onclick="DeleteSelect" text="Delete Selected records" runat="server" />
<asp:label id="errMsg" runat="server" />
      <ASP:DataGrid id="staffShow" runat="server"
        BorderColor="black"
        BorderWidth="1"
        GridLines="Both"
        CellPadding="3"
        CellSpacing="0"
        Font-Name="Verdana"
        Font-Size="9pt"
	DataKeyField="SID"
	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="SID" DataField="SID" ItemStyle-Wrap="false"/>
	<asp:BoundColumn HeaderText="Name" DataField="cname"/>
	<asp:BoundColumn HeaderText="PID" DataField="pid"/>
	<asp:TemplateColumn HeaderText="Birthday" >
		<ItemTemplate>
			<asp:Label runat="server" Text=<%# DataBinder.Eval(Container.DataItem, "Bday","{0:yyyy/MM/dd}") %> id="Bday"/>
		</ItemTemplate>
	</asp:TemplateColumn>
	<asp:TemplateColumn HeaderText="Department" >
		<ItemTemplate>
			<asp:Label runat="server" Text=<%# DataBinder.Eval(Container.DataItem, "Content") %> id="Content"/>
		</ItemTemplate>
	</asp:TemplateColumn>
	</Columns>
</ASP:DataGrid>
</form>