Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/263.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的动态表单获取数据 private void createnewTable(int-ts,int-sid) { SubjectClass s1=新的SubjectClass(); List sub=新列表(); sub=s1.返回主题列表(sid); 表时间表=新表(); 整数高度=20; Panel1.Attributes.Add(“样式”,“高度:”+height.ToString()+“px;”); 对于(inti=1;i_C#_Asp.net - Fatal编程技术网

C# 从具有多个dropdownlist的动态表单获取数据 private void createnewTable(int-ts,int-sid) { SubjectClass s1=新的SubjectClass(); List sub=新列表(); sub=s1.返回主题列表(sid); 表时间表=新表(); 整数高度=20; Panel1.Attributes.Add(“样式”,“高度:”+height.ToString()+“px;”); 对于(inti=1;i

C# 从具有多个dropdownlist的动态表单获取数据 private void createnewTable(int-ts,int-sid) { SubjectClass s1=新的SubjectClass(); List sub=新列表(); sub=s1.返回主题列表(sid); 表时间表=新表(); 整数高度=20; Panel1.Attributes.Add(“样式”,“高度:”+height.ToString()+“px;”); 对于(inti=1;i,c#,asp.net,C#,Asp.net,您正面临此错误,因为动态创建的控件在回发后会被刷新。您需要重新创建它们以使其可用,或者您可以使用其他方法。例如,在单击按钮时从javascript访问下拉列表并在js中使用。您可以将其结果存储在隐藏字段中,该字段将在代码中可用印第安纳州 检查此链接: private void createnewTable(int ts,int sid) { SubjectClass s1 = new SubjectClass(); List<string> sub = new Li


您正面临此错误,因为动态创建的控件在回发后会被刷新。
您需要重新创建它们以使其可用,或者您可以使用其他方法。
例如,在单击按钮时从javascript访问下拉列表并在js中使用。您可以将其结果存储在隐藏字段中,该字段将在代码中可用印第安纳州

检查此链接:

private void createnewTable(int ts,int sid)
{
    SubjectClass s1 = new SubjectClass();
    List<string> sub = new List<string>();
    sub = s1.returnSubjectList(sid);

    Table timetable = new Table();
    int height = 20;
    Panel1.Attributes.Add("style", "height:" + height.ToString() + "px;");
    for (int i = 1; i <= ts; i++)
    {
        height = height + 20;
        TableRow tr = new TableRow();
        TableCell td1 = new TableCell();
        Label lbl = new Label();
        lbl.Text = "Lecture" + (i).ToString();
        td1.Controls.Add(lbl);
        tr.Controls.Add(td1);
        for (int j = 1; j <= 6; j++)
        {
            TableCell td2 = new TableCell();
            DropDownList drop_sub = new DropDownList();
            drop_sub.ID = "drop" + i.ToString() + j.ToString();
            foreach (string s in sub)
            {
                drop_sub.Items.Add(s.ToString());
            }
            drop_sub.Items.Add("No lecture");
            td2.Controls.Add(drop_sub);
            tr.Controls.Add(td2);
            Panel1.Attributes.Add("style", "height:" + height.ToString() + "px;");

        }

        timetable.Controls.Add(tr);

    }
    panel_timetable.Controls.Add(timetable);
}
protected void btn_save_Click(object sender, EventArgs e)
{
    int totsub = int.Parse(Session["ts"].ToString());
    Session["ts"] = null;
    List<string> sub = new List<string>();
    for (int i = 1; i <= totsub; i++)
    {
        for (int j = 1; j <= 6; j++)
        {
            DropDownList drop = new DropDownList();
            drop = (DropDownList)(panel_timetable.FindControl("drop"+i.ToString()+j.ToString()));//here error that Object reference                     //not set to an instance of an object.
            string str = drop.SelectedValue;
            sub.Add(str);
        }
    }
}