ASP.NET 2.0项目-根据类型动态生成的控件? [英] ASP.NET 2.0 project - dynamically generated control based on type?

查看:37
本文介绍了ASP.NET 2.0项目-根据类型动态生成的控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正在处理旧版ASP.NET 2.0项目.

Working on a legacy ASP.NET 2.0 project.

有人知道免费的动态控件会根据分配给它的类型来呈现自己吗?

Anyone know of a free dynamic control that will render itself based upon the type it's assigned to?

例如,如果我将其传递给DateTime属性,则应将其呈现为日期时间选择器.如果我给它一个字符串...一个简单的文本框.给它一个列表,它将创建一个下拉列表或列表框...

For example, if I pass it a DateTime property, it should render as a date time picker. If I give it a string... a simple text box. Give it a list, and it will create a dropdown or listbox...

那里一定有东西...

There has to be something out there...

推荐答案

我无法想象会有什么东西可以做的一切.

I can't image there would be something out there that can just do everything.

您肯定可以将很多控件包装到一个可以通用键入的控件中

You could definitely wrap a lot of controls into one control that you could generically type

public class ControlLoader<T> : System.Web.UI.Control where T : Type 
{
    public T Value { get; set; }

    protected override void Render(System.Web.UI.HtmlTextWriter writer)
    {
        if (typeof(T) == typeof(DateTime))
        {
            Controls.Add(/* some datetime picker you found */);
        }
        else if (...)
        { 
            //
        }            
        base.Render(writer);
    }        
}

这篇关于ASP.NET 2.0项目-根据类型动态生成的控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆