道不远人,深入.net底层技术
业精于勤荒于嬉,行成于思毁于随!

在绑定CheckBoxList后,使用如下JS获取值不成功

for(var i=0;i<chkObj.length;i++)
{

     if(chkObj.checked)
          valueList += ',' + chkObj[i].value;

}

这样并不能获取到想要的值

因为CheckBoxList返回到客户端时没有value属性

奇怪的是,我在后台指定了:DataValueField = "Guid" 但是在客户端找不到GUID的值

===============

无奈,我只好改装一下后台: 添加属性的方法

string strchkValue = "";
string strchkText = "";
for(int i=0;i<ds.Tables[0].Rows.Count;i++)
{

     strchkValue += ds.Tables[0].Rows[i]["Guid"].ToString() + ",";
     strchkText += ds.Tables[0].Rows[i]["UserID"].ToString() + ",";
}
strchkValue = strchkValue.TrimEnd(',');
strchkText = strchkText .TrimEnd(',');

chklistUser.Attributes.Add("chkValue",strchkValue );
chklistUser.Attributes.Add("chkText",strchkText );

然后,在客户端使用如下语句就可以获到取值了(说白了,就是把值放到属性里面)

for(var i=0;i<...; i++)
{
     value += ',' + document.getElementById(chkName).attributes['chkValue'].value.split(',')[i]
}

 

 

 

posted on 2008-10-16 09:57  扬帆起航  阅读(8777)  评论(0编辑  收藏  举报