ASP.NET 中 RadioButtonList的实例

RadioButtonListValidation.aspx
  1. <%@ Page Language="C#" %>  
  2.   
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  4.   
  5. <script runat="server">  
  6.     protected void Button1_Click(object sender, EventArgs e)  
  7.     {  
  8.         Label1.Text = "Your favorite: ";  
  9.         Label1.Text += RadioButtonList1.SelectedItem.Text.ToString();  
  10.     }  
  11. </script>  
  12.   
  13. <html xmlns="http://www.w3.org/1999/xhtml">  
  14. <head id="Head1" runat="server">  
  15.     <title>asp.net RequiredFieldValidator example: how to validate RadioButtonList</title>  
  16. </head>  
  17. <body>  
  18.     <form id="form1" runat="server">  
  19.     <div>  
  20.         <h2 style="color:Green">RadioButtonList Validation</h2>  
  21.         <asp:Label   
  22.             ID="Label1"  
  23.             runat="server"  
  24.             Font-Size="Large"  
  25.             ForeColor="Crimson"  
  26.             >  
  27.         </asp:Label>  
  28.         <br /><br />  
  29.         <asp:Label   
  30.             ID="Label2"  
  31.             runat="server"  
  32.             Text="Favorite"  
  33.             Font-Bold="true"  
  34.             ForeColor="DodgerBlue"  
  35.             >  
  36.         </asp:Label>  
  37.         <asp:RadioButtonList   
  38.             ID="RadioButtonList1"  
  39.             runat="server"  
  40.             RepeatColumns="3"  
  41.             BackColor="DodgerBlue"  
  42.             ForeColor="AliceBlue"  
  43.             BorderColor="DarkBlue"  
  44.             BorderWidth="2"  
  45.             >  
  46.             <asp:ListItem>CheckBoxList</asp:ListItem>  
  47.             <asp:ListItem>TreeView</asp:ListItem>  
  48.             <asp:ListItem>Button</asp:ListItem>  
  49.             <asp:ListItem>SqlDataSource</asp:ListItem>  
  50.             <asp:ListItem>GridView</asp:ListItem>  
  51.             <asp:ListItem>Calendar</asp:ListItem>  
  52.             <asp:ListItem>BulletedList</asp:ListItem>  
  53.         </asp:RadioButtonList>  
  54.         <asp:RequiredFieldValidator   
  55.             ID="ReqiredFieldValidator1"  
  56.             runat="server"  
  57.             ControlToValidate="RadioButtonList1"  
  58.             ErrorMessage="Select your favorite!"  
  59.             >  
  60.         </asp:RequiredFieldValidator>  
  61.         <br />  
  62.         <asp:Button   
  63.             ID="Button1"   
  64.             runat="server"   
  65.             ForeColor="DodgerBlue"   
  66.             Text="Submit Favorite"  
  67.             OnClick="Button1_Click"  
  68.             />  
  69.     </div>  
  70.     </form>  
  71. </body>  
  72. </html>  


 

 

 

 

原文地址  http://asp-net-example.blogspot.de/2009/02/aspnet-requiredfieldvalidator-example.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值