程序 for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
ListItem litem = new ListItem();
litem.Text = ds.Tables[0].Rows[i]["Ans"].ToString();
litem.Value ="A";
cbks.Items.Add(litem);
litem.Attributes.Add("onclick", "showMoreHint()");
Panel1.Controls.Add(cbks);
}浏览器效果 <div id="Panel1" style="height:150px;width:98%;">
<table id="ctl10" border="0">
<tr>
<td><input id="ctl10_0" type="checkbox" name="ctl10$0" onclick="showMoreHint();" value="a" /><label for="ctl10_0">职能审核</label></td>
</tr><tr>
<td><input id="ctl10_1" type="checkbox" name="ctl10$1" onclick="showMoreHint();" value="b" /><label for="ctl10_1">部门审核</label></td>
</tr><tr>
<td><input id="ctl10_2" type="checkbox" name="ctl10$2" onclick="showMoreHint();" value="c" /><label for="ctl10_2">财务审核</label></td>
</tr><tr>
<td><input id="ctl10_3" type="checkbox" name="ctl10$3" onclick="showMoreHint();" value="d" /><label for="ctl10_3">过程审核</label></td>
</tr>
</table>
</div>
{
ListItem litem = new ListItem();
litem.Text = ds.Tables[0].Rows[i]["Ans"].ToString();
litem.Value ="A";
cbks.Items.Add(litem);
litem.Attributes.Add("onclick", "showMoreHint()");
Panel1.Controls.Add(cbks);
}浏览器效果 <div id="Panel1" style="height:150px;width:98%;">
<table id="ctl10" border="0">
<tr>
<td><input id="ctl10_0" type="checkbox" name="ctl10$0" onclick="showMoreHint();" value="a" /><label for="ctl10_0">职能审核</label></td>
</tr><tr>
<td><input id="ctl10_1" type="checkbox" name="ctl10$1" onclick="showMoreHint();" value="b" /><label for="ctl10_1">部门审核</label></td>
</tr><tr>
<td><input id="ctl10_2" type="checkbox" name="ctl10$2" onclick="showMoreHint();" value="c" /><label for="ctl10_2">财务审核</label></td>
</tr><tr>
<td><input id="ctl10_3" type="checkbox" name="ctl10$3" onclick="showMoreHint();" value="d" /><label for="ctl10_3">过程审核</label></td>
</tr>
</table>
</div>
function showMoreHint()
{
var checkboxs = document.getElementById("Panel1").getElementsByTagName("input");
var values;
for(i=0;i<checkboxs.length;i++)
{
if (checkboxs[i].checked){
if (values==null){
values=checkboxs[i].value;
}
else
{
values=values+","+checkboxs[i].value;
}
}
}
document.getElementById("txtHint").innerHTML=values;
}
</script>
<td><input id="ctl10_3" type="checkbox" name="ctl10$3" onclick="showMoreHint();" value="d" />过程审核</td>
<table id="ctl10" border="0">
<tr>
<td><input id="ctl10_0" type="checkbox" name="ctl10$0" onclick="showMoreHint();" /><label for="ctl10_0">职能审核</label></td>
</tr><tr>
<td><input id="ctl10_1" type="checkbox" name="ctl10$1" onclick="showMoreHint();" /><label for="ctl10_1">部门审核</label></td>
</tr><tr>
<td><input id="ctl10_2" type="checkbox" name="ctl10$2" onclick="showMoreHint();" /><label for="ctl10_2">财务审核</label></td>
</tr><tr>
<td><input id="ctl10_3" type="checkbox" name="ctl10$3" onclick="showMoreHint();" /><label for="ctl10_3">过程审核</label></td>
</tr>
</table>
</div>
赋值给lable,,然后判断CheckBoxList选中的时候 他那个旁边lable的value 这就可以达到要求了
<asp:CheckBoxList ID="listTest" runat="server">
</asp:CheckBoxList>
<input type="button" id="btnShow" value="显示选中值" onclick="javascript:bb();" />前台js代码:<script type="text/javascript">
function bb()
{
var valuelist = ""; //保存checkbox选中值
//遍历name以listTest开头的checkbox
for(i=0;i<listTest.rows.length;i++)
{
$("input[name='listTest$"+i+"']").each(function() {
if (this.checked) {
//$(this):当前checkbox对象;
//$(this).parent("span"):checkbox父级span对象
valuelist += $("input[name='listTest$"+i+"']").parent("span").attr("alt") + ",";
}
});
}
if (valuelist.length > 0) {
//得到选中的checkbox值序列,结果为400,398
valuelist = valuelist.substring(0, valuelist.length - 1);
alert(valuelist);
}
}
后台页面:protected void Page_Load(object sender, EventArgs e)
{
string sqls = "select ADDVNM,ADDVCD from SX_ADNM_B where substring(ADDVCD,5,2)='00' and substring(ADDVCD,3,4)!='0000'";
DataTable dts = SqlHelper.ExecuteDataset(this.connStr, CommandType.Text, sqls).Tables[0]; foreach (DataRow dr in dts.Rows)
{
listTest.Items.Add(new ListItem(dr["ADDVNM"].ToString(), dr["ADDVCD"].ToString()));
} foreach (ListItem li in listTest.Items)
{
li.Attributes.Add("alt", li.Value);
} }