日期:2014-05-17  浏览次数:20515 次

多个RadioButton 的问题
页面上多个RadioButton ,包括Repeater里面的。
想做成单选效果的,设置了GroupName属性,还是没出来。上来问问
还有 像现在这样子,我后台放一个Button ,怎么取前台RadioButton的值?

代码如下:

HTML code

<fieldset>
                <legend>...Or Choose From Your Address Book Entries</legend>
                <div id="defaultSelected" class="moduleRowSelected">
                    <div class="back">
                        <asp:RadioButton ID="rds" runat="server" GroupName="yys" />
                   
                        <asp:Literal  ID="lite" runat="server"></asp:Literal>
                    </div>
                    <div class="back">
                    </div>
                </div>
                <br class="clearBoth">
                <address>
                    <asp:Literal runat="server" ID="liyl"></asp:Literal>
                </address>
                <asp:Repeater ID="rp_dl" runat="server">
                    <ItemTemplate>
                        <div id="defaultSelected" class="moduleRowSelected">
                            <div class="back">
                                <asp:RadioButton ID='rde' runat="server" GroupName="yys" />
                                <%# Eval("Y_FirstName")%><%# Eval("Y_LastName") %>
                            </div>
                            <div class="back">
                            </div>
                        </div>
                        <br class="clearBoth">
                        <address>
                            <%# Eval("Y_FirstName") %>&nbsp;
                            <%# Eval("Y_LastName") %><br />
                            <%# Eval("Y_Address")%><br />
                            <%# Eval("Y_City")%>,<%# Eval("Y_State")%>&nbsp;<%# Eval("Y_Zip")%><br /><%# Eval("Y_Country")%></address>
                    </ItemTemplate>
                </asp:Repeater>
            </fieldset>




------解决方案--------------------
肯定不行啊 这样你的id不是一样了吗?
 id是唯一的 那怎么可以循环呢?
------解决方案--------------------
遍历。。(RadioButton )RP.Items[i].FindControl(RadioButtonName)

------解决方案--------------------
C# code

protected void Button1_Click(object sender, EventArgs e)
    {
        //使用模版列里加RadioButton
        Label1.Text = "";
        foreach (GridViewRow gvr in GridView1.Rows)
        {
            try
            {
                if (((RadioButton)gvr.FindControl("RadioButton1")).Checked)
                {
                    Label1.Text = "当前选中第" + Convert.ToString(gvr.RowIndex + 1) + "个";
                    break;
                }
            }
            catch (Exception)
            { }
        }
        if (Label1.Text.Length == 0)
        {
            Label1.Text = "没有选中项";
        }
    }