<asp:Repeater ID="rpt_ente" runat="server" OnItemDataBound="rpt_ente_DataBound" >
<ItemTemplate>
<table >
<tr>
<td
选择<asp:RadioButton ID="rdb_enteid" runat="server" Text='<%#Eval("id") %>'
GroupName="radio_ente" OnCheckedChanged="rdb_enteid_Checked" AutoPostBack="true" />
</td>
<td >
<asp:Label ID="lbl_entename" runat="server" Text='<%#Eval("name") %>'></asp:Label>
</td>
<td>
<asp:Label ID="lbl_areaname" runat="server" Text='<%#Eval("areaname") %>'></asp:Label>
</td>
<td >
<asp:Label ID="lbl_phone" runat="server" Text='<%#Eval("phone") %>'></asp:Label>
</td>
<td >
<asp:Label ID="lbl_ENTEADDRESS" runat="server" Text='<%#Eval("sex") %>'></asp:Label>
</td>
<td>
<asp:Label ID="lbl_remark" runat="server" Text='<%#Eval("remark") %>'></asp:Label>
</td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
后置代码:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
int enteid = Convert.ToInt32(Request.QueryString["id"]);
Bind_rptente();
}
else
{
Bind_rptente();
}
}
protected void Bind_rptente()
{
//省略绑定代码
}
//当被选中时,循环Repeater中的单选把选择项唯一标识记录下来
protected void rdb_enteid_Checked(object sender, EventArgs e)
{
foreach (RepeaterItem i in this.rpt_ente.Items)
{
RadioButton radiocheck = (RadioButton)i.FindControl("rdb_enteid");
if (radiocheck.Checked == true)
{
string checkvalue = radiocheck.Text;
Session["checkvalue"] = checkvalue;
}
}
}
//在REPEAATER绑定行时,如果有单选按钮值与前面保存的值相同就让他选择,否则不选择
protected void rpt_ente_DataBound(object sender, RepeaterItemEventArgs e)
{
RadioButton radiocheck = (RadioButton)e.Item.FindControl("rdb_enteid");
if (Session["checkvalue"] != null)
{
string id = Session["checkvalue"].ToString();
if (radiocheck.Text == Session["checkvalue"].ToString())
{
radiocheck.Checked = true;
}
else
{
radiocheck.Checked = false;
}
}
}
我是这样想的,但还是不行。
如果设置单选按钮
AutoPostBack="true"
并且回发再去绑定的话,一个也选不中,
如果回发,那就成了多选。
repeater 中如何实现 单选