📄 databindexample.aspx
字号:
<HTML>
<HEAD>
<title>将 Hashtable 绑定到 RadioButtonList Web 控件示例</title>
<script language="C#" runat="server">
void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
// 创建 Hashtable 对象并填充数据
Hashtable hash = new Hashtable();
hash.Add("北京", "010");
hash.Add("广州", "020");
hash.Add("上海", "021");
hash.Add("天津", "022");
hash.Add("成都", "028");
hash.Add("济南", "0531");
// 进行数据绑定
RadioButtonList1.DataSource = hash;
RadioButtonList1.DataTextField = "Key";
RadioButtonList1.DataValueField = "Value";
RadioButtonList1.DataBind();
}
}
void SubmitBtn_Click(object sender, System.EventArgs e)
{
Label1.Text = "区号是:" + RadioButtonList1.SelectedValue;
}
</script>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<h3>将Hashtable绑定到RadioButtonList Web控件示例</h3>
<asp:RadioButtonList id="RadioButtonList1" runat="server"></asp:RadioButtonList>
<asp:Button id="SubmitBtn" runat="server" Text="查看区号" OnClick="SubmitBtn_Click"></asp:Button>
<br>
<br>
<asp:Label id="Label1" runat="server">Label</asp:Label>
</form>
</body>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -