ASP.NET data bind two-way, bi-directional from code behind

Posted by Konrad on Stack Overflow See other posts from Stack Overflow or by Konrad
Published on 2010-05-20T06:13:22Z Indexed on 2010/05/20 6:20 UTC
Read the original article Hit count: 235

Filed under:
|

Hello, so for two-way (bi-directional) databinding in ASP, we do this...

<asp:textbox id="txtField" runat="server" 
    text='<%# Bind("SomeField") %>'>
</asp:textbox>

SomeField is located on the DataSource of the DetailsView that serves as the container for the textbox.

Alternatively I could do this from code-behind (using the textbox's OnDataBinding event):

protected void SomeField_OnDataBinding(object sender, EventArgs e)
{ 
  ((TextBox)sender).Text = Eval("SomeField").ToString();
}

However, EVAL is read-only...how can I specify Bind (two-way) from code-behind?

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about databinding