protected void AddLayer() { if (Session["ProjectCode"].ToString() != "") { PlaceHolder1.Controls.Clear(); //先清除所有子控制項 string[] data = WebModel.Get_PWBS_LayerKind(Session["DatabaseName"].ToString(), Session["ProjectCode"].ToString()); string[] LayerNum = new string[1]; string[] LayerKind = new string[1]; if (data[1] != null && data[2] != null) { LayerNum = data[1].Split(','); LayerKind = data[2].Split(','); if (ViewState["ADD"] == null) { //Section1_Click(this, null); if (LayerNum[0] != null) { ViewState["i"] = int.Parse(LayerNum.Max()); } for (int i = 0; i < int.Parse(ViewState["i"].ToString()); i++) { DropDownList ddl = new DropDownList(); ddl.ID = i.ToString(); ddl.DataSourceID = "SqlDataSource1"; ddl.DataTextField = "OrderName"; ddl.DataValueField = "Kind"; //ddl.DataBind(); y = i + 1; ddl.AutoPostBack = true; ddl.SelectedIndexChanged += itemselect_indexchange; PlaceHolder1.Controls.Add(new LiteralControl("<tr><td class=\"auto-style13\">第 " + y + " 階</td><td class=\"auto-style14\">")); PlaceHolder1.Controls.Add(ddl); //ddl.Items.Insert(0, new ListItem("-請選擇-", "0")); PlaceHolder1.Controls.Add(new LiteralControl("</td></tr>")); ViewState["layer"] = y; Session["layer"] = y; } if (LayerNum[0] != null) { for (int i = 0; i < int.Parse(LayerNum.Max()); i++) { DropDownList DDL = (DropDownList)PlaceHolder1.FindControl(i.ToString()); if (DDL != null) { DDL.SelectedValue = LayerKind[i]; } } } } else { for (int i = 0; i < int.Parse(ViewState["i"].ToString()); i++) { DropDownList ddl = new DropDownList(); ddl.ID = i.ToString(); ddl.DataSourceID = "SqlDataSource1"; ddl.DataTextField = "OrderName"; ddl.DataValueField = "Kind"; //ddl.DataBind(); int y = i + 1; // ddl.AutoPostBack = true; ddl.SelectedIndexChanged += itemselect_indexchange; PlaceHolder1.Controls.Add(new LiteralControl("<tr><td class=\"auto-style13\">第 " + y + " 階</td><td class=\"auto-style14\">")); PlaceHolder1.Controls.Add(ddl); //ddl.Items.Insert(0, new ListItem("-請選擇-", "0")); PlaceHolder1.Controls.Add(new LiteralControl("</td></tr>")); this.ViewState["ADD"] = true; //Pnl_Layer.Visible = true; ViewState["layer"] = y; Session["layer"] = y; } for (int i = 0; i < int.Parse(LayerNum.Max()); i++) { DropDownList DDL = (DropDownList)PlaceHolder1.FindControl(i.ToString()); if (DDL != null) { DDL.SelectedValue = LayerKind[i]; } } } //ViewState["layer"] = y; //Session["layer"] = y; } else { if (LayerNum[0] == null) { LayerNum = new string[1] { "1" }; LayerKind = new string[1] { "1" }; } for (int i = 0; i < int.Parse(ViewState["i"].ToString()); i++) { DropDownList ddl = new DropDownList(); ddl.ID = i.ToString(); ddl.DataSourceID = "SqlDataSource1"; ddl.DataTextField = "OrderName"; ddl.DataValueField = "Kind"; //ddl.DataBind(); int y = i + 1; // ddl.AutoPostBack = true; ddl.SelectedIndexChanged += itemselect_indexchange; PlaceHolder1.Controls.Add(new LiteralControl("<tr><td class=\"auto-style13\">第 " + y + " 階</td><td class=\"auto-style14\">")); PlaceHolder1.Controls.Add(ddl); //ddl.Items.Insert(0, new ListItem("-請選擇-", "0")); PlaceHolder1.Controls.Add(new LiteralControl("</td></tr>")); this.ViewState["ADD"] = true; ViewState["layer"] = y; Session["layer"] = y; } for (int i = 0; i < int.Parse(LayerNum.Max()); i++) { DropDownList DDL = (DropDownList)PlaceHolder1.FindControl(i.ToString()); if (DDL != null) { DDL.SelectedValue = LayerKind[i]; } } } } else { ScriptManager.RegisterStartupScript((System.Web.UI.Page)HttpContext.Current.Handler, this.GetType(), "ShowMessage", "alert('請先選擇專案');", true); } }
protected void AddLayer() { if (Session["Bid"] == null) { Response.Write("<script>alert('尚未選擇標案');self.close();</script>"); } else { PlaceHolder1.Controls.Clear(); //先清除所有子控制項 string[] data = WebModel.Get_WBS_LayerKind(Session["DatabaseName"].ToString(), Session["BID"].ToString()); //string[] LayerNum = data[1].Split(','); //string[] LayerKind = data[2].Split(','); string[] LayerNum = new string[1]; string[] LayerKind = new string[1]; if (data[1] != null && data[2] != null) { LayerNum = data[1].Split(','); LayerKind = data[2].Split(','); if (ViewState["ADD"] == null) { //Section1_Click(this, null); //if (Session["layer"] != null && Session["layer"]!="") //{ ViewState["i"] = int.Parse(ViewState["layer"].ToString()); //} } for (int i = 0; i < int.Parse(ViewState["i"].ToString()); i++) { DropDownList ddl = new DropDownList(); ddl.ID = i.ToString(); ddl.DataSourceID = "SqlDataSource1"; ddl.DataTextField = "OrderName"; ddl.DataValueField = "Kind"; //ddl.DataBind(); int y = i + 1; //ddl.AutoPostBack = true; ddl.SelectedIndexChanged += itemselect_indexchange; //ddl.DataBind(); PlaceHolder1.Controls.Add(new LiteralControl("<tr><td class=\"auto-style13\">第 " + y + " 階</td><td class=\"auto-style14\">")); PlaceHolder1.Controls.Add(ddl); //ddl.Items.Insert(0, new ListItem("-請選擇-", "0")); PlaceHolder1.Controls.Add(new LiteralControl("</td></tr>")); //ddl = (DropDownList)PlaceHolder1.FindControl(i.ToString()); } this.ViewState["ADD"] = true; for (int i = 0; i < int.Parse(LayerNum.Max()); i++) { DropDownList DDL = (DropDownList)PlaceHolder1.FindControl(i.ToString()); if (DDL != null) { DDL.SelectedValue = LayerKind[i]; } } //} } else { if (LayerNum[0] == null) { LayerNum = new string[1] { "1" }; LayerKind = new string[1] { "1" }; } for (int i = 0; i < int.Parse(ViewState["i"].ToString()); i++) { DropDownList ddl = new DropDownList(); ddl.ID = i.ToString(); ddl.DataSourceID = "SqlDataSource1"; ddl.DataTextField = "OrderName"; ddl.DataValueField = "Kind"; //ddl.DataBind(); int y = i + 1; // ddl.AutoPostBack = true; ddl.SelectedIndexChanged += itemselect_indexchange; PlaceHolder1.Controls.Add(new LiteralControl("<tr><td class=\"auto-style13\">第 " + y + " 階</td><td class=\"auto-style14\">")); PlaceHolder1.Controls.Add(ddl); //ddl.Items.Insert(0, new ListItem("-請選擇-", "0")); PlaceHolder1.Controls.Add(new LiteralControl("</td></tr>")); } for (int i = 0; i < int.Parse(LayerNum.Max()); i++) { DropDownList DDL = (DropDownList)PlaceHolder1.FindControl(i.ToString()); if (DDL != null) { DDL.SelectedValue = LayerKind[i]; } } } } }