Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/61.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# C asp.net使用mysql数据库值动态创建多个复选框_C#_Mysql_Asp.net - Fatal编程技术网

C# C asp.net使用mysql数据库值动态创建多个复选框

C# C asp.net使用mysql数据库值动态创建多个复选框,c#,mysql,asp.net,C#,Mysql,Asp.net,我试图创建多个复选框,其值为mysql database fetched rows,比如说,如果我在DB中有10行,那么我需要在一个div中动态创建10个复选框 我不知道如何做到这一点,但我已经做了一个苗条的代码,其中添加了一个,在每次提取后 string constr = ConfigurationManager.ConnectionStrings["ConnectionStrings"].ConnectionString; using (MySqlConnection con = new

我试图创建多个复选框,其值为mysql database fetched rows,比如说,如果我在DB中有10行,那么我需要在一个div中动态创建10个复选框

我不知道如何做到这一点,但我已经做了一个苗条的代码,其中添加了一个,在每次提取后

string constr = ConfigurationManager.ConnectionStrings["ConnectionStrings"].ConnectionString;


using (MySqlConnection con = new MySqlConnection(constr))
{

    using (MySqlCommand MySqlCommand = new MySqlCommand("SELECT FatherFullName FROM xxxxxx where sssss='xxxxx'", con))
    {
        MySqlCommand.CommandType = CommandType.Text;
        con.Open();
        MySqlDataReader MySqlDataReader = MySqlCommand.ExecuteReader();
        var list = new List<string>();
        while (MySqlDataReader.Read())
        {

            string name = MySqlDataReader["FatherFullName"].ToString();
            if (!String.IsNullOrEmpty(name))
                list.Add(name);



        }
        con.Close();



    }
}

我建议使用asp.net CheckBoxList控件,假设其名称为CheckBoxList1,然后声明Datatable并获取要绑定到datatables对象中的数据

using (MySqlCommand MySqlCommand = new MySqlCommand("SELECT FatherFullName FROM xxxxxx where sssss='xxxxx'", con))
    {
        MySqlCommand.CommandType = CommandType.Text;
        con.Open();
        DataTable dt = MySqlCommand.ExecuteTable();
        if(dt.Rows.Count > 0)
        {
           CheckBoxList1.DataSource = dt;
           CheckBoxList1.DataTextField = "Title";
           CheckBoxList1.DataValueField = "ArticleID";
           CheckBoxList1.DataBind();
        }

                   con.Close();   

    }

感谢您的回复,但我有一个问题,所有复选框将投影到哪里,还有一个问题是DataTable dt=MySqlCommand.ExecuteTable;不应提供可执行文件。请使用此答案从列表中绑定复选框列表。