我有一个问题,页面上有很多个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>就如上面代码所示 可能会有很多个这样的label和RadioButtonList 我要把 label所对应的ID 和 RadioButtonList 所对应的选项都写进数据库,但是在后台我不知道一共有多少个这样的label和RadioButtonList 。因为他是通过数据库自动生成的。所以有什么办法去存呢???求高手解答 谢谢啦~
<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 。因为他是通过数据库自动生成的。所以有什么办法去存呢???求高手解答 谢谢啦~
解决方案 »
- asp.net静态页面留言功能怎么实现?
- 为什么GridView绑定后,不显示?
- 在自定义类中如何添加注释说明信息
- 数据量很大时 Hashtable 会影响速度吗?
- 求助:DataGrid中的编辑按钮"edit" 中的updatecommand事件问题
- 请问如何将 textbox里的值转换成数据库中 money 类型的值
- 请问URL重写时,文件夹不存在怎么办?
- ******请各位高手和各位大版主进来帮忙,我想让radiobuttonlist绑定的时候某几项目不可编辑。*************
- DataList编辑项中DropDownList控件的使用?
- asp.net 时间控件
- MVC URL传参问题
- 防抓取
<asp:RadioButtonList 既然Label和RadioButtonList 是1对1的关系,这个就得看成一个块,如果你全部的label和radioButtonList都堆到<asp:Panel ID="checkboxlist">里面,那你的label和RadioButtonList生成的时候, ID之间就得有一个关联约定
<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>
protected void Button1_Click(object sender, EventArgs e)
{
ControlCollection col = checkboxlist.Controls;
foreach (Control c in col)
{
if (c != null && c is Label)
{
Label lblObj = (Label)c;
string[] arr = lblObj.ID.Split('_');
if (arr.Length > 1)
{
Control cl = Page.FindControl("RadioButtonList" + arr[1]);
if (cl != null && cl is RadioButtonList)
{
RadioButtonList radlObj = (RadioButtonList)cl;
Response.Write(string.Format("title:{0} select:{1}<br>", lblObj.Text, radlObj.SelectedItem));
}
}
}
}
}
result:title:办公装备1 select:良好
title:办公装备2 select:一般
表1 lable表
labelID 名字
1 办公装备
2 办公环境表2 选项表
ID labelID 选项Text 选项Value
1 1 良好 1
2 1 一般 2
3 2 优秀 1
4 2 一般 2表3 模板表
ID 模板ID lableID
1 1 1
2 1 2表4 具体对象表
ID lableID 选项Value 模板ID 对象ID
1 1 1 审核表1各位觉得这样设计行吗?求评价~求帮忙。
绑定数据源的时候直接将查询的结果绑定上,然后在设置一下DataValueField 和DataTextField,
这个样子在存入数据库中的时候也好获取值,而且操作比较方便, 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);自己去创建控件,也可以用用户控件呀,想要多少个,就循环多少次,变一下里面的参数就可以了呀
protected void Button1_Click(object sender, EventArgs e)
{
ControlCollection col = checkboxlist.Controls;
foreach (Control c in col)
{
if (c != null && c is Label)
{
Label lblObj = (Label)c;
string[] arr = lblObj.ID.Split('_');
if (arr.Length > 1)
{
Control cl = Page.FindControl("RadioButtonList" + arr[1]);
if (cl != null && cl is RadioButtonList)
{
RadioButtonList radlObj = (RadioButtonList)cl;
//添加数据的方法
Response.Write(string.Format("title:{0} select:{1}<br>", lblObj.Text, radlObj.SelectedItem));
}
}
}
}
}
aspx(或者ascx、master page等)本来就是模板。你是在设计窗口上写定义,在代码部分写其它的、仅用声明而不能实现的功能嘛。模板的文本跟代码是封装在一起相互协调的。那种只考虑一个简单文本替换的所谓“模板”,功能是最初级的,没有考虑你续写代码以及各种高级编程的需求。
ID 模板ID lableID
1 1 1
2 1 2表4 具体对象表
ID lableID 选项Value 模板ID 对象ID
1 1 1 审核表1
改为表3 模板表
ID lableID
1 1
2 2表4 具体对象表
ID 选项表ID 模板表ID 对象ID
1 1 1 审核表1你的选项表ID是唯一值,已经可以标识某一条labelid和其value,模板表一个id就好了,虽然我不知道你的具体需求是什么
表4 具体对象表
ID lableID 选项Value 模板ID 对象ID
1 1 1 审核表1
具体对象表里面的一行