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

后端 未结 2 837
南旧
南旧 2020-12-16 23:00

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



        
相关标签:
2条回答
  • 2020-12-16 23:25

    I've managed to find a work-around for my "edge-case".

    I am using LLBLGen subtypes and therefore need to switch the datasource of the detailsview based on a radiobutton filter selected by the user.

    I tried to bind to the sub type field "declaratively" in ASP using <%# Bind(... This did not work.

    I had to resolve to a code-behind "hack" where I conditionally display the controls in the detailsview using details_view pre-render method.

    For each field I then conditionally setup it's one-way (read-only) bind in OnDataBinding...

    e.g. ((TextBox)sender).Text = Eval("FilePrefix").ToString();
    

    Finaly to get the data to push into the datasource, I hack the DetailsView OnItemInserting/Updating events (conditionally as well)...

    e.Values["FilePrefix"] = txtFilePrefix.Text;
    

    I feel so dirty after this hack I think I need a shower...

    I still hope someone can provide a cleaner approach :-)

    0 讨论(0)
  • 2020-12-16 23:49

    Did you check out this page on MSDN, Walkthrough: Editing and Inserting Data in Web Pages with the DetailsView Web Server Control ?

    0 讨论(0)
提交回复
热议问题