這表明沒有錯誤,如何插入動態創建的標籤文本到SQL Server在asp.net C#
但值沒有插入到SQL Server中.....
我們如何可以訪問從EventDuration_DDL_SelectedIndexChanged動態生成的標籤和複選框在Wizard_buttonClick()()
protected void EventDuration_DDL_SelectedIndexChanged(object sender, EventArgs e)
{
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();
CheckBox newcheck = new CheckBox();
newcheck.ID = "CheckBox" + i;
newcheck.CheckedChanged += new EventHandler(this.CheckBox_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/>"));
}
}
protected void Wizard1_FinishButtonClick(object sender, WizardNavigationEventArgs e)
{
con.Open();
var label = Labeldiv.FindControl("Label1") as Label;
var checkbox = Labeldiv.FindControl("CheckBox1") as CheckBox;
using (SqlCommand cmd2 = new SqlCommand("insert into EventDays(EventDay,EventStatus)values(@EventDay,@EventStatus)", con))
{
var paramDay = cmd2.Parameters.Add("@EventDay", SqlDbType.DateTime);
var paramStatus = cmd2.Parameters.Add("@EventStatus", SqlDbType.Int);
if (label != null)
{
paramDay.Value = label;
paramStatus.Value = checkbox.Checked ? 1 : 0;
cmd2.ExecuteNonQuery();
}
}
con.Close();
}
這是什麼問題? –
請澄清一下您的問題? – Karan
與@DavidPilkington相同的評論,如果您正在執行此代碼,您是否遇到任何錯誤?, –