Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/307.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.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
C# 具有双向绑定的ASP.NET简单自定义控件_C#_Asp.net_Custom Controls_Data Binding - Fatal编程技术网

C# 具有双向绑定的ASP.NET简单自定义控件

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

我有两个文本框和一个下拉列表的自定义控件。我想使其成为双向数据绑定,所以当我将其放入ie.Details视图控件时,如下所示:

    <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;
        }
    }
这正是我所需要的。

你应该看看——当涉及到双向数据绑定控件时,我不确定是否有这么简单的东西。你应该看看——当涉及到双向数据绑定控件时,我不确定是否有这么简单的东西。