在Aspx文件中:
<asp:RadioButtonList ID="rblSex" runat="server" RepeatDirection="Horizontal">
<asp:ListItem Value="Boy">男</asp:ListItem>
<asp:ListItem Value="Girl">女</asp:ListItem>
</asp:RadioButtonList>
在CS文件:
protected System.Web.UI.WebControls.RadioButtonList rblSex;
//绑定性别
this.rblSex.DataSource = this.GetData(1,"staff","Sex");//取得数据集
this.rblSex.DataValueField = "Value";
this.rblSex.DataTextField = "Item";
this.rblSex.DataBind();
//读取姓别
for(int i=0;i<this.rblSex.Items.Count;i++)
{
if(this.rblSex.Items[i].Value == DataTable.Row[i][0])
{
this.rblSex.SelectedItem.Selected = false;
this.rblSex.Items[i].Selected = true;
}
}