111,129
社区成员
发帖
与我相关
我的任务
分享
protected void CheckBoxList_DataBound(object sender, EventArgs e)
{
CheckBoxList chkList = sender as CheckBoxList;
foreach (ListItem item in chkList.Items)
{
if (......)
{
item.Selected = true;
}
}
}
protected void Page_Load(object sender, EventArgs e)
{
CheckBoxList1.Items[0].Selected = true;
CheckBoxList1.Items[1].Selected = true;
}
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:CheckBoxList ID="CheckBoxList1" runat="server" Width="169px">
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
</asp:CheckBoxList>
</div>
</form>
</body>
</html>