Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
asp.net中的自定义文本框控件_Asp.net_Controls - Fatal编程技术网

asp.net中的自定义文本框控件

asp.net中的自定义文本框控件,asp.net,controls,Asp.net,Controls,我正在尝试在itlike textmode中创建一个带有枚举种类属性的自定义文本框。枚举值将来自数据库。但是枚举不能是动态的..还有别的办法吗 最接近的是整数属性。枚举是编译时常量。如果数据库值在运行时不会更改,则始终可以使用codegen工具在预编译时从数据库生成枚举值。如果它们将发生更改,您可能只需要执行字符串属性或类似操作,而不是枚举。您必须编写自定义类型转换器来完成此任务 public class MyItemsConverter : TypeConverter { publi

我正在尝试在itlike textmode中创建一个带有枚举种类属性的自定义文本框。枚举值将来自数据库。但是枚举不能是动态的..还有别的办法吗

最接近的是整数属性。

枚举是编译时常量。如果数据库值在运行时不会更改,则始终可以使用codegen工具在预编译时从数据库生成枚举值。如果它们将发生更改,您可能只需要执行字符串属性或类似操作,而不是枚举。

您必须编写自定义类型转换器来完成此任务

public class MyItemsConverter : TypeConverter
{

    public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
    {
        StringCollection values = new StringCollection();

        // Connect to database and read values.

        return new StandardValuesCollection(values);
    }

    public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
    {
        return (context != null);
    }

    public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
    {
        return true;
    }

}

您好,欢迎回复!代码可以工作,但是当从下拉列表中选择一个值时,每次单击GetStandardValues都会调用两次…哪里出错了???@anay,你是对的。虽然它只在设计时发生,但并不重要。无论如何,您可以缓存数据以提高性能。
public class MyControl : WebControl
{

    [TypeConverter(typeof(MyItemsConverter))]
    public string MyItem { get; set; }

}