<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>未命名頁面</title>
<script language="JavaScript" src="js/Calendar.js"></script>
<LINK href="../style/css.css" type="text/css" rel="stylesheet">
<LINK href="../style/css1.css" type="text/css" rel="stylesheet">
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
<asp:Button ID="Button4" runat="server" OnClick="Button4_Click" Text="Button" />
<table>
<tr>
<td>異常代碼</td>
<td>開始時間</td>
<td>結束時間</td>
</tr>
<asp:Repeater ID="Repeater1" runat="server" >
<ItemTemplate>
<tr>
<td>
<asp:DropDownList ID="DropDownList2" runat="server">
</asp:DropDownList>
</td>
<td>
<input id="Text1" type="text" Text='<%#DataBinder.Eval(Container.DataItem,"FSTARTDATE") %>' οnfοcus="setday(this)"/>
</td>
<td>
<input id="Text2" type="text" Text='<%#DataBinder.Eval(Container.DataItem,"FENDDATE") %>' οnfοcus="setday(this)"/>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
<tr style="display:none">
<td> <asp:DropDownList ID="DropDownList3" runat="server">
</asp:DropDownList></td>
<td> <input id="Text4" type="text" runat=server /></td>
<td> <input id="Text3" type="text" runat=server /></td>
</tr>
</table>
</div>
</form>
</body>
</html>
cs:
public string[] FCODE = { "AK", "AL", "AR", "AW" };
public string[] Mystates = { "AK", "AL", "AR", "AW" };
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
CreateTable();
}
}
public void Button1_Click(object sender, EventArgs e)
{
addLine();
Text3.Value = "";
Text4.Value = "";
}
protected void Button4_Click(object sender, EventArgs e)
{
DelLine();
bindtype();
}
public void addLine()//增加一行
{
DataTable dt = new DataTable("newtable");
dt = (DataTable)Session["newtable"];
DataRow dr;
dr = dt.NewRow();
dr["FSTARTDATE"] = "";
dr["FSTARTDATE"] = Text3.Value;
dr["FENDDATE"] = Text4.Value;
dt.Rows.Add(dt);
Session["newtable"] = dt;
this.Repeater1.DataSource = dt;
this.Repeater1.DataBind();
bindtype();
}
private void bindtype()//綁定下拉框
{
// Hashtable ht = new Hashtable();
// ht.Add(1, "字符串型");
// ht.Add(2, "整型");
foreach (System.Web.UI.WebControls.RepeaterItem item in Repeater1.Items)
{
DropDownList dp = (DropDownList)item.FindControl("DropDownList2");
dp.DataSource = FCODE;
//dp.DataTextField = "value";
//dp.DataValueField = "key";
// dp.DataSource = Mystates;
dp.DataBind();
}
}
public void DelLine()//刪除一行
{
DataTable dt = (DataTable)Session["newtable"];
if (dt.Rows.Count - 1 >= 0)
{
dt.Rows.RemoveAt(dt.Rows.Count - 1);
}
Repeater1.DataSource = dt;
Repeater1.DataBind();
}