关于asp.net 的CheckBoxList控件生成HTML不带value的解决方案

作者:ChiKun 时间:

关于asp.net 的CheckBoxList控件生成HTML不带value的解决方案,问题如下:

C#代码:

if (dt != null && dt.Rows.Count > 0)
{
    foreach (DataRow dr in dt.Rows)
    {
        //分别为text值、value值
        listTest.Items.Add(new ListItem(dr["Title"].ToString(), dr["ID"].ToString()));
    }
}
生成的HTML代码:

<table id="cblRole" border="0">
<tbody>
<tr>
<td><input id="cblRole_0" type="checkbox" name="cblRole$0"><label for="cblRole_0">系统管理员</label></td>
<td><input id="cblRole_1" type="checkbox" name="cblRole$1"><label for="cblRole_1">VM管理员</label></td>
<td><input id="cblRole_2" type="checkbox" name="cblRole$2"><label for="cblRole_2">部门经理</label></td>
<td><input id="cblRole_3" type="checkbox" name="cblRole$3"><label for="cblRole_3">最终用户</label></td>
</tr>
</tbody></table>

里面完全看不到value值,明明设置了的。。
以前经常遇到这个问题,一直没想到好的解决方案,今天遇到了,记录下,以免以后找不到
在webconfig中找到
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID" />

把这个注释掉就可以了。