asp.net Dictionary, Key, Value example: using System.Collections.Generic
DictionaryExample.aspx
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Collections.Generic" %>
<!DOCTYPE html>
<script runat="server">
protected void Page_Load(object sender, System.EventArgs e){
if(!Page.IsPostBack){
Dictionary<int, string> Controls = new Dictionary<int, string>();
Controls.Add(1,"Button");
Controls.Add(2,"AdRotator");
Controls.Add(3,"BulletedList");
Controls.Add(4,"Calendar");
Controls.Add(5,"CheckBoxList");
Controls.Add(6,"DropDownList");
Controls.Add(7,"RadioButton");
Controls.Add(8,"RadioButtonList");
CheckBoxList1.DataSource = Controls;
CheckBoxList1.DataTextField = "Value";
CheckBoxList1.DataValueField = "Key";
CheckBoxList1.DataBind();
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>asp.net Dictionary, Key, Value example: using System.Collections.Generic</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:Teal">Dictionary Example</h2>
<asp:CheckBoxList
ID="CheckBoxList1"
runat="server"
RepeatColumns="3"
BorderWidth="2"
BackColor="HotPink"
ForeColor="AliceBlue"
BorderColor="LightPink"
>
</asp:CheckBoxList>
</div>
</form>
</body>
</html>