怎么实现动态生成控件,然后获取值
求助如何实现动态生成控件,然后获取值
现在项目需要一个动态生成表单的功能
我一开始的实现如下
.aspx文件生成表单代码块
.aspx.cs文件生成表单代码块
现在项目需要一个动态生成表单的功能
我一开始的实现如下
.aspx文件生成表单代码块
<table>
<asp:Repeater ID="BrandList" runat="server">
<ItemTemplate>
<tr>
<th>
<%#Eval("t_name") %>:
</th>
<td>
<%#Eval("TypeName")%> : <%#out_table(int.Parse(Eval("Id").ToString()),
Eval("t_name").ToString(),Eval("inputType").ToString(),
Eval("xuanxiang").ToString(),
int.Parse(Eval("required").ToString()))%>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
.aspx.cs文件生成表单代码块
protected void Page_Load(object sender, EventArgs e)
{
thisGod = this;
if (!IsPostBack)
{
if (!string.IsNullOrEmpty(Request.QueryString["id"].ToString()))
{
//int TypeId = setid();
//box.TypeId = TypeId;
//box.createTime = DateTime.Now;
string wheresql = "TypeId = " + TypeId.ToString();
this.BrandList.DataSource = DAL.tableType.GetList(wheresql);
this.BrandList.DataBind();
}
}
}
public string out_table(int ControlId, string t_name, string inputType, string xuanxiang,int required)
{
box.List.Add(new tableBase() { name = (t_name +"_"+ ControlId.ToString()),Value = "",ControlId = ControlId});
string inputstring = "";
if (inputType == "text")
{
inputstring = "<input id=\"" + t_name + "_" + ControlId + "\"" + " type=\"text\" runat=\"server\" ";
if (required == 1)
{
inputstring += "required=\"required\" ";
}
inputstring += "/>";
}
if (inputType == "textarea")