繁体   English   中英

从asp.net转发器检查html单选按钮ID

[英]checked html radio button id from asp.net repeater

我试图到达html单选按钮ID和asp中继器中的另一个值,这是我的代码:

<asp:Repeater runat="server" ID="rpt_Departure_Schedule">
    <ItemTemplate>
        <tr class="schedules  <%#disable_Class (Eval("Seat_Count")) %>" data-schedule="Departure" data-route_class_id="<%#Eval("Flight_ID") %><%#Eval("Ticket_Price_Name_Sub_ID") %>" data-section="Schedule">
            <td class="schedules-selection ui-tablecolumn-global-schedules">
                <span class="uroute_class_id radio ui-sprite-global" data-schedule="Departure" data-active="<%#Eval("Seat_Count") %>">
                    <input id="<%#Eval("Schedule_Number") %>" type="radio" name="radDepartureRoute_Class_ID" value="<%#Eval("Schedule_ID") %><%#Eval("Ticket_Price_Name_Sub_ID") %>" /></span>
            </td>
            <td class="schedule "><%#Eval("Schedule_Number") %></td>
            <td class="date "><%#Eval("Date") %></td>
            <td class="departure-time "><%#Eval("Time") %></td>
            <td class="departure-location "><%#Eval("Departure_Code") %></td>
            <td class="schedule-class "><%#Eval("Ticket_Price_Name_Sub_ID") %></td>
        </tr>
    </ItemTemplate>
</asp:Repeater>

如何获取所选单选按钮的ID和所选行的<td class="schedule-class "><%#Eval("Ticket_Price_Name_Sub_ID") %></td>值?

我建议使用JQuery来实现具有良好性能的相同功能。

单击单选按钮时调用Javascript方法,如下所示:

<asp:Repeater runat="server" ID="rpt_Departure_Schedule">
    <ItemTemplate>
        <tr class="schedules  <%#disable_Class (Eval("Seat_Count")) %>" data-schedule="Departure" data-route_class_id="<%#Eval("Flight_ID") %><%#Eval("Ticket_Price_Name_Sub_ID") %>" data-section="Schedule">
            <td class="schedules-selection ui-tablecolumn-global-schedules">
                <span class="uroute_class_id radio ui-sprite-global" data-schedule="Departure" data-active="<%#Eval("Seat_Count") %>">
                    <input id='<%#Eval("Schedule_Number") %>' type="radio" name="radDepartureRoute_Class_ID" value="<%#Eval("Schedule_ID") %><%#Eval("Ticket_Price_Name_Sub_ID") %>" onclick="GetValues(this)" /></span>
            </td>
            <td class="schedule "><%#Eval("Schedule_Number") %></td>
            <td class="date "><%#Eval("Date") %></td>
            <td class="departure-time "><%#Eval("Time") %></td>
            <td class="departure-location "><%#Eval("Departure_Code") %></td>
            <td class="schedule-class "><%#Eval("Ticket_Price_Name_Sub_ID") %></td>
        </tr>
    </ItemTemplate>
</asp:Repeater>

并获取并设置javascript中的值,如下所述:

  function GetValues(control) {
            var Schedule_Number = control.value;
            var subject_Id = $(control).closest('tr').children('td')[5].innerText;
        }

现在您可以使用Schedule_Numbersubject_Id

protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    //write your code here.... for radiobutton select

}

在.aspx页中:使用asp:radioButton Html控件。

<asp:Repeater runat="server" ID="rpt_Departure_Schedule" OnItemDataBound="rpt_Departure_Schedule_ItemDataBound">
    <HeaderTemplate>
        <table>
    </HeaderTemplate>
    <ItemTemplate>
        <tr class="schedules" data-schedule="Departure" data-route_class_id="" data-section="Schedule">
            <td class="schedules-selection ui-tablecolumn-global-schedules">
                <span class="uroute_class_id radio ui-sprite-global" data-schedule="Departure" data-active="">
                    **<asp:RadioButton ID="radDepartureRoute_Class_ID" runat="server" />**
                </span>
            </td>
            <td class="schedule "></td>
            <td class="date "></td>
            <td class="departure-time "></td>
            <td class="departure-location "></td>
            <td class="schedule-class "></td>
        </tr>
    </ItemTemplate>
    <FooterTemplate>
        </table>
    </FooterTemplate>
</asp:Repeater>

在后面的代码中:

    protected void rpt_Departure_Schedule_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) {
            var myCheckbox = (RadioButton)e.Item.FindControl("radDepartureRoute_Class_ID");

        } 
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM