一聚教程网:一个值得你收藏的教程网站

热门教程

asp.net checkboxlist 取值实例

时间:2022-06-25 04:15:34 编辑:袖梨 来源:一聚教程网

asp教程.net checkboxlist 取值实例

checkboxlist是复选框的集合,对checkboxlist赋值是没有意义的,要对里面的选

项赋值
checkboxlist1.items.add(new listitem("文本1", "value1"));
checkboxlist1.items.add(new listitem("文本2", "value2"));

核心代码


string strapp = "当前记录,当前页,全部记录,";
string[] strtemp = strapp.split(',');
foreach (string str in strtemp)
{
 for (int i = 0; i < cbljl.items.count; i++)
 {
  if (this.cbljl.items[i].value == str)
  {
   this.cbljl.items[i].selected = true;
  }
 }
}

完整实例

<%@ page language=vb debug=true %>
<%@ import namespace="system.data" %>



checkboxlist control sample page




    id="lblmessage"
    runat="server"
    font-bold="true"
    text="preferred office color(s):"
/>
    id="cbl1"
    runat="server"
    cellpadding="5"
    cellspacing="5"
    repeatcolumns="3"
    repeatdirection="vertical"
    repeatlayout="table"
    textalign="right"
    autopostback="true"
    onselectedindexchanged="cbl1_clicked"
>
    blue
    red
    green
    purple
    black
    gold



    id="lblmessage2"
    runat="server"
    font-bold="true"
    text="id of department(s) you work in:
"
/>


    id="cbl2"
    runat="server"
    autopostback="true"
    onselectedindexchanged="cbl2_clicked"
    datatextfield="departmentname"
    datavaluefield="departmentid"
    backcolor = "lightyellow"
    forecolor = "darkred"
    bordercolor = "darkblue"
    borderstyle = 8
    textalign="left"
    repeatlayout="table"
>




热门栏目