0

2 つの入力変数に基づいて、Checkboxlist をプログラムでバインドしようとしています。しかし、チェックボックスは 3 ではなく 1 つしかありません。

これが私のコードです

これが私のビジネスレイヤーです

 public class BALDisplayPanel2
{

    private string _mylabel;

    public string MyLabel
    {
        get { return _mylabel;  }
        set { _mylabel = value; }
    }

    private string _conditionlabel;

    public string ConditionLabel
    {
        get { return _conditionlabel; }
        set { _conditionlabel = value; }
    }


    private string _checkboxquestion;

    public string CheckBoxQuestion
    {
        get { return _checkboxquestion; }
        set { _checkboxquestion = value; }
    }

これは私のデータアクセスレイヤーです

 public List<BALDisplayPanel2> DisplaySPanelQ(int tbid, int grdid)
    {

        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["mynewdbConnectionString"].ConnectionString);
        conn.Open();
        SqlCommand cmd = new SqlCommand("esp_MyCheckboxProc", conn);
        cmd.CommandType = CommandType.StoredProcedure;
        List<BALDisplayPanel2> lst = new List<BALDisplayPanel2>();
        cmd.Parameters.AddWithValue("@Emp", tbid);
        cmd.Parameters.AddWithValue("@UnitNumber", grdid);

        SqlDataReader dr = cmd.ExecuteReader();

        while (dr.Read())
        {
            BALDisplayPanel2 unt = new BALDisplayPanel2();
            unt.CheckBoxQuestion = dr["CheckQuest"].ToString();
            unt.MyLabel = dr["MyLabel"].ToString();
            unt.ConditionLabel = dr["ConditionLabel"].ToString();

            //unt.LabelS = dr["LabelQ2"].ToString();
            lst.Add(unt);
        }

        conn.Close();
        return lst;

    }

これは私のDefault.csファイルで、チェックボックスと呼んでいます

        BALDisplayPanel2 bl = new BALDisplayPanel2();
        DALDisplayPanel2 dal = new DALDisplayPanel2();
        List<BALDisplayPanel2> lst = new List<BALDisplayPanel2>();
        lst = dal.DisplaySPanelQ(Convert.ToInt32(tbEmpID.Text), Convert.ToInt32(GridView1.SelectedRow.Cells[2].Text));

        foreach (var item in lst)
        {

            chbklstpanel3.Items.Clear();
            chbklstpanel3.DataSource = lst;
            chbklstpanel3.DataTextField = item.CheckBoxQuestion;

            lblpanel3.Text = item.MyLabel;
            lblCondition.Text = item.ConditionLabel;


            }

助けてください

4

1 に答える 1

0

実際にそこで行っていることは、結果をループし、その中にチェックリストボックスをバインドすることです。したがって、ここで 3 つのレコードがある場合、3 回ループします。また、ループ内のチェックボックスリストを clear() することにも言及しました。したがって、3 回目になると、チェックボックス リストがクリアされ、最後のレコードのみがバインドされます。それが、チェックボックス リストで 1 つのレコードのみを取得していることです。

foreach ループを削除し、

    BALDisplayPanel2 bl = new BALDisplayPanel2();
    DALDisplayPanel2 dal = new DALDisplayPanel2();
    List<BALDisplayPanel2> lst = new List<BALDisplayPanel2>();
    lst = dal.DisplaySPanelQ(Convert.ToInt32(tbEmpID.Text), Convert.ToInt32(GridView1.SelectedRow.Cells[2].Text));


        chbklstpanel3.Items.Clear();
        chbklstpanel3.DataSource = lst;
        chbklstpanel3.DataTextField = item.CheckBoxQuestion;
        chbklstpanel3.DataBind();
于 2013-05-21T06:49:00.983 に答える