ASP.NET后台 存不确定个数的控件的值
我有一个问题,页面上有很多个RadioButtonList 但是这些RadioButtonList是通过数据库生成的,所以我想问的问题是,ASP.NET的后台怎么去把这些RadioButtonList所选的值 以及RadioButtonList的值 存数据库。
<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>
<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>
[解决办法]
RadioButtonList radio = new RadioButtonList(); radio.EnableViewState = true; radio.ID = dr["id"].ToString(); radio.DataSource = ds.Tables[0]; radio.DataTextField = "title"; radio.DataValueField = "id"; radio.DataBind(); this.Panel1.Controls.Add(radio);
[解决办法]