本文介绍了如何在断开连接模式下将复选框列表与数据库绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何以断开连接模式将复选框列表与数据库绑定.
我这样做....

how to bind checkboxlist with database in disconnected mode.
me doing this....

ad = new SqlDataAdapter("select * from Location where Location.City_Id=(select City_Id from City where city='" + Session["city"].ToString() + "' )", c.con);
        DataTable dt = new DataTable();
        ad.Fill(dt);
        if (dt.Rows.Count>0) 
        {
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                CheckBoxList1.DataSource = dt;
                CheckBoxList1.DataTextField = dt.Rows[i]["Location"].ToString();
                CheckBoxList1.DataValueField = dt.Rows[i]["Id"].ToString();
                CheckBoxList1.DataBind();
            }
        }


但是它给出了错误


but its giving error

DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'Bahadurgarh'.



CheckBoxList1.DataBind();

数据库



on CheckBoxList1.DataBind();

''Bahadurgarh'' and related id is available in database

推荐答案

dt.Rows[0].ItemArray[yourcolumnNo ].ToString();



您的问题解决了



your porblem is solved


if (dt.Rows.Count>0) 
{
    CheckBoxList1.DataSource = dt;
    CheckBoxList1.DataTextField = "Location";
    CheckBoxList1.DataValueField = "Id";
    CheckBoxList1.DataBind();
}


这篇关于如何在断开连接模式下将复选框列表与数据库绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 05:40