0

データリストで選択したチェックボックス行をバインドしたい..このコードを使用しましたが、すべてのレコードをバインドしません..

System.Web.UI.WebControls.CheckBox chkb = new System.Web.UI.WebControls.CheckBox();
string chkBoxIndex = string.Empty;

foreach (C1.Web.Wijmo.Controls.C1GridView.C1GridViewRow row in C1GridView1_listview.Rows)
{
    chkBoxIndex = (string)C1GridView1_listview.DataKeys[row.RowIndex].Value.ToString();
    chkb = (System.Web.UI.WebControls.CheckBox)row.FindControl("chkBxSelect");

    if (chkb.Checked == true)
    {

        cmd = new SqlCommand("select sample_code,convert(varchar(10),purchase_date,101) as purchase_date,sample_image_id,sample,image,style,descript from sample_shopping,sample_image where sample_shopping.sample_code=sample_image.sample and type='IMG' and sample_code='" + chkBoxIndex + "'", con);
        con.Open();
        SqlDataReader dr = cmd.ExecuteReader();

        if (dr.HasRows)
        {
            dr.Close();
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(dt);

            dl_search.DataSource = dt;
            dl_search.DataBind();
            con.Close();

        }
    }
4

1 に答える 1

0

foreach ループでのみバインディング データリスト。そのため、データリストに 1 つのレコードが表示されるたびに表示されます。foreach ループからデータリスト バインディングを作成する

System.Web.UI.WebControls.CheckBox chkb = new System.Web.UI.WebControls.CheckBox();
string chkBoxIndex = string.Empty;

    foreach (C1.Web.Wijmo.Controls.C1GridView.C1GridViewRow row in C1GridView1_listview.Rows)
    {
        chkBoxIndex = (string)C1GridView1_listview.DataKeys[row.RowIndex].Value.ToString();
        chkb = (System.Web.UI.WebControls.CheckBox)row.FindControl("chkBxSelect");

        if (chkb.Checked == true)
        {
          //update the table with update query like
           //update <table-name> set check='true' where sno=chkBoxIndex or insert the select records into seperate table.
           ...
        }
    }

次のようなクエリを使用して、データをデータリストにバインドします

 select * from <tablename> or where check=true

選択した行のみがデータリストに表示されるようにします。これが役立つことを願っています。

于 2012-06-25T20:55:22.913 に答える