我的双向如何可以绑定一个TextBox在ASP.NET一个code-背后的财产? [英] How can I two-way bind a TextBox to a code-behind property in ASP.NET?

查看:236
本文介绍了我的双向如何可以绑定一个TextBox在ASP.NET一个code-背后的财产?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在文本框中任何新条目:txtMyString设置该属性MyString中。缺少什么我在这里?

 < ASP:文本框ID =txtMyString文本='<%#MyString的%GT;' =服务器/>私人字符串myString的;
保护字符串MyString中{{返回的myString; } {设置myString的=价值; }}保护无效的Page_Load(对象发件人,EventArgs的发送)
{
    如果(!的IsPostBack)
        MyString的=1路测试工程;    的DataBind();
}


解决方案

如果你正在做双向绑定,您需要使用的DataBinder的bind()方法。

 < ASP:文本框ID =txtMyString文本='<%#绑定(MyString的)%>' =服务器/>

不过,我最后一次检查,这是只有在文本框是一个模板化控件,如GridView的,FormView控件或DetailsView控件内部的支持。

I cannot get any new entries in the textbox:txtMyString to set to the property MyString. What am I missing here?

<asp:TextBox ID="txtMyString" Text='<%# MyString %>' runat="server" />

private string myString;
protected string MyString { get { return myString; } set { myString = value; } }

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
        myString = "1 way test works";

    DataBind();
}

解决方案

If you're doing two-way databinding, you need to use the Bind() method of the databinder.

<asp:TextBox ID="txtMyString" Text='<%# Bind("MyString") %>' runat="server" />

However, last time I checked, this was only supported if the textbox was inside a templated control such as Gridview, FormView or DetailsView.

这篇关于我的双向如何可以绑定一个TextBox在ASP.NET一个code-背后的财产?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆