Listcontrol绑定的应用
DropDownList
CheckBoxList
RadioButtonList
ListBox
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<head runat="server">
<title>Data Binding ListBox</title>
<script language="C#" runat="server">
void Page_Load(Object sender, EventArgs e)
{
if (!IsPostBack)
{
ArrayList values = new ArrayList();
values.Add(new PositionData("Microsoft", "Msft"));
values.Add(new PositionData("Intel", "Intc"));
values.Add(new PositionData("Dell", "Dell"));
RadioButtonList1.DataSource = values;
RadioButtonList1.DataBind();
}
}
public class PositionData
{
private string name;
private string ticker;
public PositionData(string name, string ticker)
{
this.name = name;
this.ticker = ticker;
}
public string Name
{
get
{
return name;
}
}
public string Ticker
{
get
{
return ticker;
}
}
}
void SubmitBtn_Click(Object sender, EventArgs e)
{
if (RadioButtonList1.SelectedIndex > -1)
Label1.Text = "You chose: " + RadioButtonList1.SelectedValue;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<h3>Data Binding ListBox</h3>
<asp:ListBox ID="RadioButtonList1" runat="server" DataTextField="Name" DataValueField="Ticker">
</asp:ListBox>
<asp:button id="Button1"
Text="Submit"
OnClick="SubmitBtn_Click"
runat="server" />
<asp:Label id="Label1"
Font-Names="Verdana"
font-size="10pt"
runat="server"/>
</form>
</body>
</html>