C# 具有双向绑定的ASP.NET简单自定义控件
我有两个文本框和一个下拉列表的自定义控件。我想使其成为双向数据绑定,所以当我将其放入ie.Details视图控件时,如下所示:C# 具有双向绑定的ASP.NET简单自定义控件,c#,asp.net,custom-controls,data-binding,C#,Asp.net,Custom Controls,Data Binding,我有两个文本框和一个下拉列表的自定义控件。我想使其成为双向数据绑定,所以当我将其放入ie.Details视图控件时,如下所示: <asp:MyCustomControl ID="MyId" runat="server" Value1='<%# Bind("val1") %>'> </asp:MyCustomControl> private double _value = 0; [ Bindable(true, Bind
<asp:MyCustomControl ID="MyId" runat="server" Value1='<%# Bind("val1") %>'>
</asp:MyCustomControl>
private double _value = 0;
[
Bindable(true, BindingDirection.TwoWay),
Browsable(true),
DefaultValue(0),
PersistenceMode(PersistenceMode.Attribute)
]
public double Value
{
get
{
double d = 0;
Double.TryParse(ValueControlTextBox.Text,out d);
return d;
}
set
{
ValueControlTextBox.Text = String.Format("{0:0.00}", value);
_value = value;
}
}
我希望这个控件保持简单
我错过了什么 我找到了一些解决办法。控件中的属性(ascx.cs)现在如下所示:
<asp:MyCustomControl ID="MyId" runat="server" Value1='<%# Bind("val1") %>'>
</asp:MyCustomControl>
private double _value = 0;
[
Bindable(true, BindingDirection.TwoWay),
Browsable(true),
DefaultValue(0),
PersistenceMode(PersistenceMode.Attribute)
]
public double Value
{
get
{
double d = 0;
Double.TryParse(ValueControlTextBox.Text,out d);
return d;
}
set
{
ValueControlTextBox.Text = String.Format("{0:0.00}", value);
_value = value;
}
}
这可以满足我的需要。我找到了一些解决办法。控件中的属性(ascx.cs)现在如下所示:
<asp:MyCustomControl ID="MyId" runat="server" Value1='<%# Bind("val1") %>'>
</asp:MyCustomControl>
private double _value = 0;
[
Bindable(true, BindingDirection.TwoWay),
Browsable(true),
DefaultValue(0),
PersistenceMode(PersistenceMode.Attribute)
]
public double Value
{
get
{
double d = 0;
Double.TryParse(ValueControlTextBox.Text,out d);
return d;
}
set
{
ValueControlTextBox.Text = String.Format("{0:0.00}", value);
_value = value;
}
}
这正是我所需要的。你应该看看——当涉及到双向数据绑定控件时,我不确定是否有这么简单的东西。你应该看看——当涉及到双向数据绑定控件时,我不确定是否有这么简单的东西。