codice:
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
Dictionary<string, double> d = new Dictionary<string,double>();
d.Add("Microsoft",49.56);
d.Add("Sun",28.33);
d.Add("IBM",55);
d.Add("Compaq",20.74);
d.Add("Oracle",41.1);
this.CheckBoxList1.DataSource = d;
this.CheckBoxList1.DataValueField = "value";
this.CheckBoxList1.DataTextField = "key";
this.CheckBoxList1.DataBind();
}
protected void CheckBoxList1_DataBound(object sender, EventArgs e)
{
CheckBoxList l = (CheckBoxList)sender;
for (int i = 0; i < l.Items.Count; i++)
{
ListItem li = l.Items[i];
switch (li.Text)
{
case "IBM":
case "Compaq":
li.Enabled = false;
break;
}
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Pagina senza titolo</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:CheckBoxList ID="CheckBoxList1" runat="server" OnDataBound="CheckBoxList1_DataBound">
</asp:CheckBoxList>
</div>
</form>
</body>
</html>