本文介绍了将动态创建的控件数据保存到数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我试图找出如何保存动态创建的控件中捕获的数据。



所以会发生什么是在表单加载我会加载动态控件:





switch(WhichControl)

{

caseddl:

DropDownList ddl = new DropDownList();

ddl.ID = string.Format(ddList {0},icounter);

ddl.DataSource = myDataSource();

ddl.DataTextField =TextField;

ddl.DataValueField =DataField;

ddl.ClientIDMode = System.Web.UI.ClientIDMode.Static;

ddl.DataBind();

row.Cells [1] .Controls.Add(ddl);

break;

caserb:

RadioButtonList rb = new RadioButtonList();

rb.DataSource = myDataSource();

rb.DataTextField =TextField;

rb.DataValueField =DataField;

rb.ID = string.Format(rList {0} ,icounter);

rb.ClientIDMode = System.Web.UI.ClientIDMode.Static;

row.Cells [1] .Controls.Add(rb);

休息;

casetb:

TextBox tb = new TextBox();

tb.TextMode = TextBoxMode.SingleLine;

tb.ID = string.Format(textBox {0},icounter);

tb.ClientIDMode = System.We b.UI.ClientIDMode.Static;

row.Cells [1] .Controls.Add(tb);

break;



默认值:

休息;



}



现在我的问题是如何最好地阅读用户选择的选项并将其保存到数据库。



一个例子将不胜感激。当我尝试遍历页面时,我无法获得控件。



谢谢,

解决方案

Hi everyone,

I am trying to find out how I can save the data captured in dynamically created controls.

So what happens is on the form load I will load dynamic controls:


switch ("WhichControl")
{
case "ddl":
DropDownList ddl = new DropDownList();
ddl.ID = string.Format("ddList{0}", icounter);
ddl.DataSource = myDataSource();
ddl.DataTextField = "TextField";
ddl.DataValueField = "DataField";
ddl.ClientIDMode = System.Web.UI.ClientIDMode.Static;
ddl.DataBind();
row.Cells[1].Controls.Add(ddl);
break;
case "rb":
RadioButtonList rb = new RadioButtonList();
rb.DataSource = myDataSource();
rb.DataTextField = "TextField";
rb.DataValueField = "DataField";
rb.ID = string.Format("rList{0}", icounter);
rb.ClientIDMode = System.Web.UI.ClientIDMode.Static;
row.Cells[1].Controls.Add(rb);
break;
case "tb":
TextBox tb = new TextBox();
tb.TextMode = TextBoxMode.SingleLine;
tb.ID = string.Format("textBox{0}", icounter);
tb.ClientIDMode = System.Web.UI.ClientIDMode.Static;
row.Cells[1].Controls.Add(tb);
break;

default:
break;

}

now my question is how best can i read the options selected by the user and save it to the database.

An example would be greatly appreciated. When I try to loop through the page I can't get the controls.

Thanks,

解决方案


这篇关于将动态创建的控件数据保存到数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 00:39