<%@ 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" %>
<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)'结合至DataGrid
		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 '声明为Session
			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 staffShow_Del(sender as Object ,e as DataGridCommandEventArgs)
		dim Dstring as string
		dim Nowsid as string=staffShow.DataKeys(e.Item.ItemIndex).ToString()
		Dstring = "Delete From Staff where SID ='" & Nowsid & "'"
		try
			Dim UpStaff as SqlCommand=new SqlCommand(Dstring,Source)
			UpStaff.Connection.Open()
			UpStaff.ExecuteNonQuery()'执行保存
			UpStaff.Connection.Close()
			bindNew(true)
			errMsg.Text="Delete OK"
		catch
			errMsg.Text="Delete fail"
		end try
	end sub
	</script>
</head>
<body background="/aspnetdata/images/winback.gif">
<Title:TitleShow id="BookT" Runat="server" />
<form 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"
        HeaderStyle-BackColor="#aaaadd"
	DataKeyField="SID"
	AutoGenerateColumns="FALSE"
	OnDeleteCommand="staffShow_Del"
>
      <Columns>
	<asp:ButtonColumn Text="Delete" CommandName="Delete"/>
	<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>