protected void EventDuration_DDL_SelectedIndexChanged(object sender, EventArgs e)
{
con.Open();
DateTime dt = DateTime.Parse(StartDate_TB.Text);
int n = Int32.Parse(EventDuration_DDL.SelectedItem.ToString());
for (int i = 0; i < n; i++)
{
Label NewLabel = new Label();
NewLabel.ID = "Label" + i;
var eventDate = dt.AddDays(i);
NewLabel.Text = eventDate.ToLongDateString();
CheckBox newcheck = new CheckBox();
newcheck.ID = "CheckBox" + i;
newcheck.AutoPostBack = true;
newcheck.CausesValidation = false;
newcheck.CheckedChanged += new EventHandler(newcheck_CheckedChanged);
this.Labeldiv.Controls.Add(new LiteralControl("<span class='h1size'>"));
this.Labeldiv.Controls.Add(NewLabel);
this.Labeldiv.Controls.Add(new LiteralControl("</span>"));
this.Labeldiv.Controls.Add(new LiteralControl("<div class='make-switch pull-right' data-on='info'>"));
this.Labeldiv.Controls.Add(newcheck);
this.Labeldiv.Controls.Add(new LiteralControl("</div>"));
this.Labeldiv.Controls.Add(new LiteralControl("<br/>"));
}
con.Close();
}
protected void Done_Button_Click(object sender, EventArgs e)
{
int n = Int32.Parse(EventDuration_DDL.SelectedItem.ToString());
for (int i = 0; i < n; i++)
{
string labelId = "Label" + i.ToString();
Label NewLabel = (Label)this.Labeldiv.FindControl(labelId);
string checkBoxId = "Checkbox" + i.ToString();
CheckBox newcheck = (CheckBox)this.Labeldiv.FindControl(checkBoxId);
SqlCommand cmd = new SqlCommand("insert into EventDays(EventDay,EventStatus)values(@EventDay,@EventStatus)", con);
cmd.Parameters.AddWithValue("@EventDay", NewLabel.Text);
cmd.Parameters.AddWithValue("@EventStatus", newcheck.Checked ? "true" : "false");
cmd.ExecuteNonQuery();
}
con.Close();
}
我在EventDuration_DDL_SelectedIndexChanged創建的標籤&複選框動態......動態創建的複選框的選中變化事件,不會觸發
我要存儲這些檢查後,該複選框....
但CheckedChange事件未被觸發......... ??????
可能重複[創建動態的CheckBoxList並插入到數據庫(http://stackoverflow.com/questions/19976836/create-checkboxlist-dynamic-and-into-into-database) –