GridView等表格模板列绑定数据的方法

时间:2022-06-26 13:49:08
//绑定GridView每一行中的CheckBoxList
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
CheckBoxList cbl = (CheckBoxList)e.Row.FindControl("ckbCheckBox");
if (cbl != null)
{
BindCheckBoxList(cbl);
}
}
}
//绑定CheckBoxList的方法
private void BindCheckBoxList(CheckBoxList cbl)
{
string strSQL = "Select login_id,login_name from 表名 where 条件";
DataTable dt = GetData(strSQL);//这里的方法根据你自己的取数据的方法
cbl.DataSource = dt;
cbl.DataValueField = "login_id";
cbl.DataTextField = "login_name";
cbl.DataBind();
}