protected void AddOptionClick(object sender, EventArgs e) { List <string> option_a = new List <string>(); for (int j = 0; j < i; j++) { var tbTemp = LabelPlaceHolder.FindControl("tbx" + j.ToString()) as TextBox; option_a.Add(tbTemp.Text); } i++; LabelPlaceHolder.Controls.Clear(); //dynamic add textbox TextBox tb; for (int j = 0; j < i; j++) { tb = new TextBox(); tb.ID = "tbx" + j.ToString(); if (j < i - 1) { tb.Text = option_a[j].ToString(); } else { tb.Text = "請輸入option" + j.ToString(); } tb.Attributes.Add("onFocus", "if (this.value=='" + tb.Text + "'){this.value='';}"); tb.Attributes.Add("onblur", "if (this.value==''){this.value='" + tb.Text + "';}"); LabelPlaceHolder.Controls.Add(tb); LabelPlaceHolder.Controls.Add(new LiteralControl("<br>")); } }
protected void AddOption(string option_In) { List <string> option_a = new List <string>(); for (int j = 0; j < i; j++) { try { var tbTemp = LabelPlaceHolder.FindControl("tbx" + j.ToString()) as TextBox; option_a.Add(tbTemp.Text); } catch (Exception exep) { exep.ToString(); break; } } i++; LabelPlaceHolder.Controls.Clear(); //dynamic add textbox TextBox tb; for (int j = 0; j < i; j++) { tb = new TextBox(); tb.ID = "tbx" + j.ToString(); if (j < i - 1) { try { tb.Text = option_a[j].ToString(); } catch (Exception exep) { exep.ToString(); break; } } else { tb.Text = option_In; }/* * if (is_VoteRecord) * { * tb.Enabled = false; * }*/ LabelPlaceHolder.Controls.Add(tb); LabelPlaceHolder.Controls.Add(new LiteralControl("<br>")); } }
protected void AddOptionClick(Object sender, EventArgs e) { List <string> option_a = new List <string>(); for (int j = 0; j < i; j++) { var tbTemp = LabelPlaceHolder.FindControl("tbx" + j.ToString()) as TextBox; option_a.Add(tbTemp.Text); } i++; LabelPlaceHolder.Controls.Clear(); //dynamic add textbox TextBox tb; for (int j = 0; j < i; j++) { tb = new TextBox(); tb.ID = "tbx" + j.ToString(); if (j < i - 1) { tb.Text = option_a[j].ToString(); } else { tb.Text = "請輸入option" + j.ToString(); } /* * if (is_VoteRecord) * { * tb.Enabled = false; * }*/ LabelPlaceHolder.Controls.Add(tb); LabelPlaceHolder.Controls.Add(new LiteralControl("<br>")); } }
protected void BuildClick(Object sender, EventArgs e) { //delete and add new //check null if (CheckNull(TextBox1) && CheckNull(TextBox2) && CheckNull(StartDate) && CheckNull(EndDate) && CheckNull(TextBox1)) { for (int j = 0; j < i; j++) { var tb = LabelPlaceHolder.FindControl("tbx" + j.ToString()) as TextBox; if (tb == null) { Literal1.Text = "Please input completely"; return; } if (CheckNull(tb)) { Literal1.Text = "Successful!"; } else { Literal1.Text = "Please input completely"; return; } } } else { Literal1.Text = "Please input completely"; return; } //delete string SQLDelete = @"Delete FROM Online_Polling_DB.dbo.[vote] WHERE topic = @value1 ;"; ConnectString = Getconnectionstring("mySqlConnectionName"); MySqlConnect = new SqlConnection(ConnectString); MySqlConnect.Open(); SqlCommand MyCommand = new SqlCommand(SQLDelete, MySqlConnect); MyCommand.Parameters.AddWithValue("@value1", ModifyTopic); //執行SQL 語法 MyCommand.ExecuteNonQuery(); //add for (int k = 0; k < i; k++) { string SQLinsert = @"INSERT INTO Online_Polling_DB.dbo.[vote] ([host_id],[topic],[description],[option],[is_registered],[startdate],[enddate],[permission]) VALUES(@value1, @value2, @value3, @value4, @value5, @value6, @value7, @value8)"; MyCommand = new SqlCommand(SQLinsert, MySqlConnect); HttpCookie myCookie = Request.Cookies["cook"]; string userID = ""; try { if (myCookie.Values["UserID"] != null) { userID = myCookie.Values["UserID"]; } else { Literal1.Text = "Please input completely"; return; } } catch (Exception exce) { Literal1.Text = exce.ToString(); exce.ToString(); return; } MyCommand.Parameters.AddWithValue("@value1", userID); MyCommand.Parameters.AddWithValue("@value2", TextBox1.Text); MyCommand.Parameters.AddWithValue("@value3", TextBox2.Text); var tbTemp = LabelPlaceHolder.FindControl("tbx" + k.ToString()) as TextBox; MyCommand.Parameters.AddWithValue("@value4", tbTemp.Text); MyCommand.Parameters.AddWithValue("@value5", CheckBoxList1.Items.FindByValue("記名/不記名").Selected); MyCommand.Parameters.AddWithValue("@value6", StartDate.Text); MyCommand.Parameters.AddWithValue("@value7", EndDate.Text); string permissionTemp = ""; for (int j = 1; j <= 4; j++) { if (CheckBoxList1.Items[j].Selected == true) { permissionTemp += "1"; } else { permissionTemp += "0"; } } MyCommand.Parameters.AddWithValue("@value8", permissionTemp); //執行SQL INSERT 語法 MyCommand.ExecuteNonQuery(); Literal1.Text = "Successful!"; BuildButton.Enabled = false; } Literal1.Text = "修改完成"; }