有两个方法结合ASP.NET简单的自定义控制 [英] ASP.NET simple custom control with two way binding
本文介绍了有两个方法结合ASP.NET简单的自定义控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个文本框自定义的控制和一个下拉列表。我希望把它的双向绑定的数据,所以当我把它放到IE浏览器。详细信息视图控制是这样的:
I have custom control with two textboxes and one drop down list. I want to make it two-way data bound, so when I put it into ie. Details View control like this:
<asp:MyCustomControl ID="MyId" runat="server" Value1='<%# Bind("val1") %>'>
</asp:MyCustomControl>
那么它应该工作像普通文本框。
then it should work like regular TextBox..
在我的控制我已经值1
定义:
In my control I have Value1
defined:
[
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;
}
}
我想这种控制,以保持简单。
I want this control to keep simple.
我在想什么?
推荐答案
我找到某种解决办法的。控制(ascx.cs)的属性现在看起来是这样的:
I've found some kind of workaround. The property in control (ascx.cs) now looks like this:
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;
}
}
和的作品,因为我需要。
And that works as I need.
这篇关于有两个方法结合ASP.NET简单的自定义控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文