我已经根据 DropDownList 的选择创建了标签和复选框,并且这些值必须在仅检查到 sql 服务器后存储,请指导我......
SqlCommand cmd2 = new SqlCommand("insert into EventDays(EventDay,EventStatus)values(@EventDay,@EventStatus)");
protected void EventDuration_DDL_SelectedIndexChanged(object sender, EventArgs e)
{
var paramDay = cmd2.Parameters.Add("@EventDay", SqlDbType.DateTime);
var paramStatus = cmd2.Parameters.Add("@EventStatus", SqlDbType.Int);
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 = Calendar1.SelectedDate.Date.AddDays(i);
NewLabel.Text = eventDate.ToLongDateString();
NewLabel.CssClass = "h1size";
CheckBox newcheck = new CheckBox();
newcheck.ID = "CheckBox" + i;
newcheck.CheckedChanged += new EventHandler(this.CheckBox_CheckedChanged);
this.Labeldiv.Controls.Add(NewLabel);
this.Checkboxdiv.Controls.Add(newcheck);
this.Labeldiv.Controls.Add(new LiteralControl("<br/>"));
paramDay.Value = eventDate;
paramStatus.Value = newcheck.Checked ? 1 : 0;
}
}
private void CheckBox_CheckedChanged(object sender, EventArgs e)
{
con.Open();
cmd2.Connection = con;
cmd2.ExecuteNonQuery();
con.Close();
}