<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="RepeatedValueBinding" %>
Untitled Page
File: Default.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class RepeatedValueBinding : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
Hashtable ht = new Hashtable(3);
ht.Add("value1", "Key1");
ht.Add("value2", "Key2");
ht.Add("value3", "Key3");
Select1.DataSource = ht;
Select2.DataSource = ht;
Listbox1.DataSource = ht;
DropdownList1.DataSource = ht;
CheckList1.DataSource = ht;
OptionList1.DataSource = ht;
Page.DataBind();
}
protected void cmdGetSelection_Click(object sender, EventArgs e)
{
if (Select1.SelectedIndex != -1)
Result.Text += "- Item selected in Select1: " + Select1.Items[Select1.SelectedIndex].Text + " - " + Select1.Value + "
";
if (Select2.SelectedIndex != -1)
Result.Text += "- Item selected in Select2: " + Select2.Items[Select2.SelectedIndex].Text + " - " + Select2.Value + "
";
if (Listbox1.SelectedIndex != -1)
Result.Text += "- Item selected in Listbox1: " + Listbox1.SelectedItem.Text + " - " + Listbox1.SelectedItem.Value + "
";
if (DropdownList1.SelectedIndex != -1)
Result.Text += "- Item selected in DropdownList1: " + DropdownList1.SelectedItem.Text + " - " + DropdownList1.SelectedItem.Value + "
";
if (OptionList1.SelectedIndex != -1)
Result.Text += "- Item selected in OptionList1: " + OptionList1.SelectedItem.Text + " - " + OptionList1.SelectedItem.Value + "
";
if (CheckList1.SelectedIndex != -1)
{
Result.Text += "- Items selected in CheckList1: ";
foreach (ListItem li in CheckList1.Items)
{
if (li.Selected)
Result.Text += li.Text + " - " + li.Value + " ";
}
}
}
}