Jos*_*orp 8 html c# asp.net dynamic-data
我想从ASP.NET中的数据库动态生成表单,最好的方法是什么?我可以使用任何内置功能吗?
我将有数据库表来表示面板及其名称,然后对于每个面板,它包含不同的字段及其类型(组合,文本框等等).
请指教,谢谢.
注意:我必须使用Telerik Ajax控件来生成表单
Dam*_*isa 14
看看动态数据.
我最近发现了它,它已经为我节省了很多时间.
更新:
道歉 - 重读了这个问题,我不认为这就是你所追求的.
如果要根据数据库中的记录动态生成表单,则可能必须编写自己的引擎.
但有几点建议:
更新:有关反射的更多信息
简而言之,反射就是在运行时发现程序集的细节.在这种情况下,我建议使用反射根据数据库中的信息加载控件.
因此,如果您的数据库中有一条类似于以下内容的记录:
FieldName DataType DisplayControl DisplayProperty
----------------------------------------------------------------------------------
FirstName System.String System.Web.UI.WebControls.TextBox Text
Run Code Online (Sandbox Code Playgroud)
您可以使用以下代码在页面上生成控件(请注意,它未经测试):
// after getting the "PageItem" database records into a "pageItems" array
foreach (PageItem p in pageItems)
{
// get the type and properties
Type controlType = System.Type.GetType(p.DisplayControl)
PropertyInfo[] controlPropertiesArray = controlType.GetProperties();
// create the object
object control = Activator.CreateInstance(controlType);
// look for matching property
foreach (PropertyInfo controlProperty in controlPropertiesArray)
{
if (controlPropertiesArray.Name == p.DisplayProperty)
{
// set the Control's property
controlProperty.SetValue(control, "data for this item", null);
}
}
// then generate the control on the page using LoadControl (sorry, lacking time to look that up)
Run Code Online (Sandbox Code Playgroud)
有一个非常好的页面概述了如何在这里做到这一点.它看起来几乎就是你所追求的.
| 归档时间: |
|
| 查看次数: |
19894 次 |
| 最近记录: |