簡體   English   中英

asp net repeater單選按鈕組名稱和獲取單選按鈕值

[英]asp net repeater radio button group name and get radio button value

我在一個頁面中有一個用於銀行帳號和信用卡分期付款列表的aspx c#頁面

如果用戶想要銀行轉賬,則選擇銀行賬戶,如果用戶想要支付信用卡分期付款就行了。

問題是單選按鈕組名稱。 我沒有對單選按鈕進行分組,也沒有獲得所選的單選按鈕值。

這是我的代碼。

這是Banks銀行賬戶清單

<asp:Repeater ID="RptBankalar" runat="server">
                        <ItemTemplate>
                            <div class="BankaListBox">
                                <table width="100%" height="100" border="0" cellspacing="0" cellpadding="0">
                                    <tr>
                                        <td width="200" align="center" valign="middle">
                                            <img alt="<%#Eval("BankName").ToString() %>" src="../../Files/<%#Eval("Logo").ToString() %>" /></td>
                                        <td>
                                            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                                <tr>
                                                    <td width="120" height="22"><strong>Account Owner</strong></td>
                                                    <td width="15"><strong>:</strong></td>
                                                    <td><%#Eval("AcOwner").ToString() %></td>
                                                </tr>
                                                <tr>
                                                    <td width="120" height="22"><strong>Branch No</strong></td>
                                                    <td width="15"><strong>:</strong></td>
                                                    <td><%#Eval("Branch").ToString() %></td>
                                                </tr>
                                                <tr>
                                                    <td width="120" height="22"><strong>Account Number</strong></td>
                                                    <td width="15"><strong>:</strong></td>
                                                    <td><%#Eval("AccountNum").ToString() %></td>
                                                </tr>
                                                <tr>
                                                    <td width="120" height="22"><strong>IBAN</strong></td>
                                                    <td width="15"><strong>:</strong></td>
                                                    <td><%#Eval("Iban").ToString() %></td>
                                                </tr>
                                            </table>
                                        </td>
                                        <td width="100" align="center" valign="middle">
                                            <asp:RadioButton ID="RadioBtn" Text='<%#Eval("id").ToString() %>' runat="server" />
                                        </td>
                                    </tr>
                                </table>
                            </div>
                        </ItemTemplate>
                    </asp:Repeater>

同一頁面信用卡分期付款清單

<asp:Repeater ID="RptTaksitList" OnItemDataBound="RptTaksitList_ItemDataBound" runat="server">
                                            <ItemTemplate>
                                                <tr runat="server" id="arka_tr">
                                                    <td align="center" height="22" width="40" runat="server" id="td1">
                                                        <b style="display: none; visibility: hidden">
                                                            <asp:Literal ID="lt_id" Text='<%#Eval("BankaID").ToString() %>' runat="server"></asp:Literal>
                                                        </b>
                                                        <asp:Literal ID="lt_taksit_sayisi" Text='<%#Eval("TaksitSayisi").ToString() %>' runat="server"></asp:Literal></td>
                                                    <td width="150" runat="server" id="td2">
                                                        <asp:Literal ID="LblSepetTotal" runat="server" Text='<%#Session["SepetUrunToplami"] %>'></asp:Literal></td>
                                                    <td runat="server" id="td3"><b style="display: none; visibility: hidden">
                                                        <asp:Literal ID="lt_komisyon_orani" Text='<%#Eval("KomisyonOrani").ToString() %>' runat="server"></asp:Literal>
                                                    </b>
                                                        <asp:Literal ID="lt_toplam_tutar" runat="server" Text=''></asp:Literal>
                                                        <b style="display: none; visibility: hidden">
                                                            <asp:Literal ID="lt_alt_limit" Text='<%#Eval("AltLimit").ToString() %>' runat="server"></asp:Literal>
                                                        </b>
                                                    </td>
                                                </tr>
                                            </ItemTemplate>
                                        </asp:Repeater>

如何獲取值並將此單選按鈕分組。

通常我在經典的asp中做過,但我改變了我的編碼語言。

親切的問候。

謝謝你的幫助。

我從不在Stack中幫忙。 因此,在社區多次幫助之后,我將第一次做出貢獻。

我喜歡你。 我有一個更簡單的解決方案。

使用帶有className的元素(DIV)圍繞您的單選按鈕,您可能只想在jQuery中選擇所有無線電。

編輯:當我改變這種方式時,aspnet並沒有持久於視圖狀態。 現在它工作得很好:)

$(document).ready(function () {
    $(".radiofix").each(function () {
        var objRadiosContainer = $(this);
        objRadiosContainer.find("input[type=radio]").each(function () {
            var objRadio = $(this);
            objRadio.change(function () {
                if(objRadio.get(0).checked)
                {
                    objRadiosContainer.find("input[type=radio]").each(function () {
                        if($(this).get(0).id != objRadio.get(0).id)
                        {
                            $(this).get(0).checked = false;
                        }
                    });
                }
            });
        });
    });
});

我們來看看HTML文件(或ASPX文件):

<asp:Repeater ID="questions" runat="server">
        <ItemTemplate>
            <h3>%# getQuestionNumber() %>) <%# Eval("questionDescription").ToString() %></h3>
            <div class="nameOfTheClass">
                <asp:Repeater ID="answers" runat="server">
                    <ItemTemplate>
                        <asp:RadioButton ID="radioId" runat="server" />
                    </ItemTemplate>
                </asp:Repeater>
            </div>
        </ItemTemplate>

這你工作得很好。 只需創建一些javascript文件(.js)並調用它,fixTheRadios.js並選擇你喜歡的“nameOfTheClass”的名稱。

重要提示:我沒有在更新面板中測試代碼。 我建議你那樣做。

這是我如何做到的。

在標記中,我將單選按鈕聲明為服務器端html控件:

<input id="rbMyRadio" type="radio"runat="server" class="myClass" />

並在代碼中訪問值:

foreach (RepeaterItem item in RptBankalar.Items)
{
    if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
    {
        HtmlInputRadioButton rbMyRadio = (HtmlInputRadioButton)item.FindControl("rbMyRadio");
        if (rbMyRadio != null && rbMyRadio.Checked)
        {
            //Do tasks
        }
    }
}

使用頁眉中的jquery完成分組:

<script type="text/javascript">
    $(document).ready(function () {
        $('input[type=radio]').click(function () {
            var cname = $(this).attr('class');

            $('.' + cname).each(function () {
                $(this).prop('checked', false);
            });

            $(this).prop('checked', true);
        });
    });
</script>

並在頭部引用jquery:

<script src="Scripts/jquery-1.8.2.js"></script>

答案非常晚,但您也可以嘗試在轉發器中添加這樣的單選按鈕:

        <asp:TemplateColumn>
            <ItemTemplate>
                <div style="text-align: center">
                    <input type="radio" id="rptMyRadio" runat="server" />
                </div>
            </ItemTemplate>
        </asp:TemplateColumn>

然后在腳本塊中添加:

        $('input[type=radio]').click(function () {
            $('input[type=radio]').removeAttr("checked");
            $(this).prop('checked', true);
        });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM