检查来自asp.net转发器的html单选按钮ID

时间:2013-12-02 10:52:10

标签: c# html asp.net radio-button 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>值?

3 个答案:

答案 0 :(得分:1)

我建议使用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_Number subject_Id

答案 1 :(得分:0)

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

}

答案 2 :(得分:0)

<。>在.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");

        } 
    }