日期:2014-05-18  浏览次数:20426 次

ASP.NET后台 存不确定个数的控件的值
我有一个问题,页面上有很多个RadioButtonList 但是这些RadioButtonList是通过数据库生成的,所以我想问的问题是,ASP.NET的后台怎么去把这些RadioButtonList所选的值 以及RadioButtonList的值 存数据库。

C# code
<asp:Panel ID="checkboxlist" runat="server">
        <asp:Label runat="server" ID="11">办公装备</asp:Label>
        <asp:RadioButtonList ID="RadioButtonList1" runat="server" 
            RepeatDirection="Horizontal">
            <asp:ListItem Value="0">良好</asp:ListItem>
            <asp:ListItem Value="1">一般</asp:ListItem>
            <asp:ListItem Value="2">尚可</asp:ListItem>
        </asp:RadioButtonList>
    </asp:Panel>


就如上面代码所示 可能会有很多个这样的label和RadioButtonList 我要把 label所对应的ID 和 RadioButtonList 所对应的选项都写进数据库,但是在后台我不知道一共有多少个这样的label和RadioButtonList 。因为他是通过数据库自动生成的。所以有什么办法去存呢???求高手解答 谢谢啦~


------解决方案--------------------
放到一个容器中如DateList,循环显示,循环存储
------解决方案--------------------
<asp:Label runat="server" ID="11">办公装备</asp:Label>
<asp:RadioButtonList 

既然Label和RadioButtonList 是1对1的关系,这个就得看成一个块,如果你全部的label和radioButtonList都堆到<asp:Panel ID="checkboxlist">里面,那你的label和RadioButtonList生成的时候, ID之间就得有一个关联约定

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

    <form id="form1" runat="server">
    <asp:Panel ID="checkboxlist" runat="server">
        <asp:Label runat="server" ID="lbl_1">办公装备1</asp:Label>
        <asp:RadioButtonList ID="RadioButtonList1" runat="server" RepeatDirection="Horizontal">
            <asp:ListItem Value="0">良好</asp:ListItem>
            <asp:ListItem Value="1">一般</asp:ListItem>
            <asp:ListItem Value="2">尚可</asp:ListItem>
        </asp:RadioButtonList>
        <asp:Label runat="server" ID="lbl_2">办公装备2</asp:Label>
        <asp:RadioButtonList ID="RadioButtonList2" runat="server" RepeatDirection="Horizontal">
            <asp:ListItem Value="0">良好</asp:ListItem>
            <asp:ListItem Value="1">一般</asp:ListItem>
            <asp:ListItem Value="2">尚可</asp:ListItem>
        </asp:RadioButtonList>
    </asp:Panel>
    <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
    </form>

------解决方案--------------------
探讨

C# code

<form id="form1" runat="server">
<asp:Panel ID="checkboxlist" runat="server">
<asp:Label runat="server" ID="lbl_1">办公装备1</asp:Label>
<asp:RadioButtonList ID="RadioBu……

------解决方案--------------------
你可以把你的这些数据放入到数据库中,然后把你想要的数据显示在radiobuttonlist,
绑定数据源的时候直接将查询的结果绑定上,然后在设置一下DataValueField 和DataTextField,
这个样子在存入数据库中的时候也好获取值,而且操作比较方便,
C# code

                    RadioButtonList radio = new RadioButtonList();
                    radio.EnableViewState = true;
                    radio.ID = dr["id"].ToString();
                    radio.DataSource = ds.Tables[0];
                    radio.DataTextField = "title";
                    radio.DataValueField = &quo