Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.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
Asp.net 绑定datalist中的数据_Asp.net_Ajax_Web Services_C# 4.0 - Fatal编程技术网

Asp.net 绑定datalist中的数据

Asp.net 绑定datalist中的数据,asp.net,ajax,web-services,c#-4.0,Asp.net,Ajax,Web Services,C# 4.0,我想绑定datalist中选定的复选框行..我使用了此代码,但没有绑定所有记录 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)

我想绑定datalist中选定的复选框行..我使用了此代码,但没有绑定所有记录

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();

        }
    }

您的绑定数据列表仅在foreach循环中。这就是为什么它每次都会显示数据列表中的一条记录。使数据列表绑定脱离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.
           ...
        }
    }
现在使用如下查询将数据绑定到datalist

 select * from <tablename> or where check=true

这样,datalist中将只显示选定的行。希望这会有所帮助。

仅最后一条记录绑定。。如何在数据列表中绑定更多记录如何使用此代码在数据列表中绑定多行\jadarnel27///您能解决此问题吗?您是否将复选框的autopostback属性设置为true?是不是一个问题…我的问题是如何添加多条记录绑定数据列表