求救 asp.net CheckBoxList从数据库读取数据设定是否选中,急急急

[复制链接]
查看11 | 回复4 | 2009-3-17 22:16:50 | 显示全部楼层 |阅读模式
页面



无标题页











"

SelectCommand="SELECT * FROM [test]">





当前记录

当前页

全部记录







后台
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{

protected void Page_Load(object sender, EventArgs e)

{

if (!IsPostBack)

{

string name = "当前记录,当前页,";

string[] names;

names = name.Split(',');

foreach (string str in names)

{


for (int i = 0; i < cblJL.Items.Count; i++)

{

if (this.cblJL.Items.Value == str)

{

this.cblJL.Items.Selected = true;

}

}

}

foreach (string str in names)

{

for (int i = 0; i < CheckBoxList1.Items.Count; i++)

{

if (this.CheckBoxList1.Items.Value == str)

{

this.CheckBoxList1.Items.Selected = true;

}

}

}

}

}
}
为什么第一个从数据库中绑定数据的无法设定为是否选中啊!!!

回复

使用道具 举报

千问 | 2009-3-17 22:16:50 | 显示全部楼层
你是从数据库读取,那么你数据库里面这个字段应该为0或1,你在后台写,如果为0,那么这个CheckBox就为false,否则为true就行了啊,本来就是bool值,你读取出来就这两个结果,判断下很简单的嘛...
回复

使用道具 举报

千问 | 2009-3-17 22:16:50 | 显示全部楼层
protected void Page_Load(object sender, EventArgs e) { string name ="当前记录,当前页,"; string[] strtemp = name.Split(',');
foreach (string str in strtemp)
...
回复

使用道具 举报

千问 | 2009-3-17 22:16:50 | 显示全部楼层
this.CheckBoxList1.Items.Selected = true;...
回复

使用道具 举报

千问 | 2009-3-17 22:16:50 | 显示全部楼层
应该不能这样设置,,要也是设置selectindex......
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行