从数据列表中获取单选按钮的值 [英] get value of radio button from datalist

查看:108
本文介绍了从数据列表中获取单选按钮的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<asp:DataList ID="DataList1" runat="server" OnItemDataBound="DataList1_ItemDataBound" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Horizontal">
        <FooterStyle BackColor="#CCCC99" ForeColor="Black" />
        <HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />
        <ItemTemplate>
            <table class="auto-style1">
                <tr>
                    <td>
                        <asp:Label ID="Label1" runat="server" Text="Q1."></asp:Label>
                    </td>
                    <td colspan="4">
                        <asp:Label ID="Label2" runat="server" Text='<%# Bind("Q1") %>'></asp:Label>
                    </td>
                </tr>
                <tr>

                    <td colspan="4">
                        <asp:RadioButtonList ID="RadioButtonList1" runat="server">
                        </asp:RadioButtonList>
                    </td>
                </tr>

                <tr>
                    <td>
                        <asp:Label ID="Label3" runat="server" Text="Q2."></asp:Label>
                    </td>
                    <td colspan="4">
                        <asp:Label ID="Label4" runat="server" Text='<%# Bind("Q2") %>'></asp:Label>
                    </td>
                </tr>
                <tr>

                     <td>
                         <asp:RadioButtonList ID="RadioButtonList2" runat="server">
                         </asp:RadioButtonList>
                     </td>

                </tr>
                 <tr>
                    <td>
                        <asp:Label ID="Label5" runat="server" Text="Q3."></asp:Label>
                    </td>
                    <td colspan="4">
                        <asp:Label ID="Label6" runat="server" Text='<%# Bind("Q3") %>'></asp:Label>
                    </td>
                </tr>
                <tr>

                     <td>
                         <asp:RadioButtonList ID="RadioButtonList3" runat="server">
                         </asp:RadioButtonList>
                     </td>

                </tr>
                 <tr>
                    <td>
                        <asp:Label ID="Label7" runat="server" Text="Q4."></asp:Label>
                    </td>
                    <td colspan="4">
                        <asp:Label ID="Label8" runat="server" Text='<%# Bind("Q4") %>'></asp:Label>
                    </td>
                </tr>
                <tr>

                     <td>
                         <asp:RadioButtonList ID="RadioButtonList4" runat="server">
                         </asp:RadioButtonList>
                     </td>


                </tr>
                <tr>
                    <td>&nbsp;</td>
                    <td colspan="4">
                        <asp:Button ID="Button2" runat="server" Text="Submit" />
                    </td>
                </tr>
            </table>
        </ItemTemplate>
        <SelectedItemStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />

    </asp:DataList>

推荐答案

您可以使用
You can access the radio button using DataListItem.FindControl()[^]
You can do something like-
RadioButtonList rbtnlist=( RadioButtonList)DataList1.Items[0].FindControl("RadioButtonList1"));


这将使您从数据列表的第一项中获得单选按钮列表.您可以使用for或foreach循环遍历所有行以查找所有值.

希望对您有帮助:)


This will get you the radiobuttonlist from the first item of the datalist. You may iterate through all the rows using for or foreach loop to find all the values.

Hope, it helps :)


这篇关于从数据列表中获取单选按钮的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆