学习顺序:1、如何绑定数据  2、如何设置绑定项  3、如何取出数据

 

1、RadioButton - 单选按钮  RadioButtonList - 单选按钮组

控件中的ID生成了相同名字的 ID、Name、Value

编译前

<asp:RadioButton ID="RadioButton1" runat="server" Text="男" />
<asp:RadioButton ID="RadioButton2" runat="server" Text="女" />

页面展示  单选按钮之间不互斥,自动生成name,默认name不同(李献策lxc)

C#-WebForm-复合控件

编译后

<input id="RadioButton1" type="radio" name="RadioButton1" value="RadioButton1" /><label for="RadioButton1">男</label>
<input id="RadioButton2" type="radio" name="RadioButton2" value="RadioButton2" /><label for="RadioButton2">女</label>

 属性:

  GroupName - 分组

<asp:RadioButton ID="RadioButton1" runat="server" Text="" GroupName="sex" />
<asp:RadioButton ID="RadioButton2" runat="server" Text="" GroupName="sex" />

 

RadioButtonList - 单选按钮组(李献策lxc)

一、绑定数据

新建一个类

C#-WebForm-复合控件

1、自带构造函数  2、没有命名空间

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        List<States> slist = new List<States>();

        States s1 = new States() { Code = "001", Name = "张店" };
        States s2 = new States() { Code = "002", Name = "淄川" };
        States s3 = new States() { Code = "003", Name = "博山" };
        States s4 = new States() { Code = "004", Name = "桓台" };
        States s5 = new States() { Code = "005", Name = "临淄" };
        States s6 = new States() { Code = "006", Name = "周村" };

        slist.Add(s1);
        slist.Add(s2);
        slist.Add(s3);
        slist.Add(s4);
        slist.Add(s5);
        slist.Add(s6);

        RadioButtonList1.DataSource = slist;
        RadioButtonList1.DataTextField = "Name";
        RadioButtonList1.DataValueField = "Code";
        RadioButtonList1.DataBind();

    }
    
}
为复选按钮组绑定信息

相关文章: