Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 我创建了标签&;复选框基于DropDownList的选择,并且这些值必须仅在签入sql server后存储_C#_Asp.net - Fatal编程技术网

C# 我创建了标签&;复选框基于DropDownList的选择,并且这些值必须仅在签入sql server后存储

C# 我创建了标签&;复选框基于DropDownList的选择,并且这些值必须仅在签入sql server后存储,c#,asp.net,C#,Asp.net,我已经根据DropDownList的选择创建了标签和复选框,并且这些值只能在签入sql server后存储 请引导我 SqlCommand cmd2 = new SqlCommand("insert into EventDays(EventDay,EventStatus)values(@EventDay,@EventStatus)"); protected void EventDuration_DDL_SelectedIndexChanged(object sender, EventArgs

我已经根据DropDownList的选择创建了标签和复选框,并且这些值只能在签入sql server后存储 请引导我

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();
}
SqlCommand cmd2=新的SqlCommand(“插入EventDays(EventDay,EventStatus)值(@EventDay,@EventStatus)”;
受保护的void EventDuration\u DDL\u SelectedIndexChanged(对象发送方,事件参数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());
对于(int i=0;i”);
paramDay.Value=eventDate;
paramStatus.Value=newcheck.Checked?1:0;
}
}
私有无效复选框\u CheckedChanged(对象发送方,事件参数e)
{
con.Open();
cmd2.Connection=con;
cmd2.ExecuteNonQuery();
con.Close();
}

这一行似乎有一个问题

int n = Int32.Parse(EventDuration_DDL.SelectedItem.ToString());
“SelectedItem”不是数字-您需要获取SelectedItem的值

int n = Int32.Parse(EventDuration_DDL.SelectedItem.Value.ToString());

你有什么错误吗?当您尝试编译并运行此文件时,会发生什么情况?