【发布时间】:2011-08-25 17:03:58
【问题描述】:
我有两个文本框和一个下拉列表的自定义控件。我想让它成为双向数据绑定,所以当我把它放入 ie.详情查看控件如下:
<asp:MyCustomControl ID="MyId" runat="server" Value1='<%# Bind("val1") %>'>
</asp:MyCustomControl>
那么它应该像普通的 TextBox 一样工作..
在我的控制下,我定义了Value1:
[
Bindable(true, BindingDirection.TwoWay),
Browsable(true),
DefaultValue(0),
PersistenceMode(PersistenceMode.Attribute)
]
public double Value1
{
get
{
if(ViewState["Value1"]==null)
return 0;
return (double)ViewState["Value1"];
}
set
{
ViewState["Value1"] = value;
}
}
我希望这个控件保持简单。
我错过了什么?
【问题讨论】:
-
你应该看看Developing Custom Data-Bound Web Server Controls——说到双向数据绑定控件,我不确定是否有这么简单的东西。
标签: c# asp.net custom-controls data-binding