Bidirectional Data Binding?

  • Thread starter Thread starter Aquila Deus
  • Start date Start date
A

Aquila Deus

Hi all!

I'm wondering if I can code like this with .NET 2:

<asp:Repeater runat="server" DataSource="Articles" Item="article">
...
<asp:TextBox runat="server" Field="article.Subject"/>
<p>
<asp:TextBox runat="server" Multiline="true" Field="article.Text"/>
</p>
...
</asp:Repeater>

Articles is an IEnumerable of article class in Page, and "article" in
Repeater is just a variable assigned to current item when walking
through the datasource.

I'd like to have ASP.NET automatically bind the input to properties in
article automatically (with given converter if needed). I have read a
few about the ObjectDataSource etc but all of those *Views seem to be
designed for special purpose...

If it can't do so, is there any framework other than Spring.NET does
that? (otherwise I'll have to extend all those controls myself...)
 
I've done similar sorts of things with a GridView.

<asp:GridView ID="gvArticles" runat="server" DataSourceID="dsArticles"
AutoGenerateColumns="False" ShowHeader="False">
<Columns>
<asp:TemplateField>
<ItemTemplate>
...
<%#Eval("Subject")%>
<p>
<%#Eval("Text")%>
</p>
...
</ItemTemplate>
<EditItemTemplate>
...
<asp:TextBox ID="fldSubject" runat="server"
Text='<%#Bind("Subject")%>' />
<p>
<asp:TextBox ID="fldText" runat="server" Multiline="True"
Text='<%#Bind("Text")%>' />
</p>
...
</EditItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" CausesValidation="true">
<ItemStyle Width="50px" />
</asp:CommandField>
</asp:GridView>

In order to use this, you'll need one of the *DataSource components,
named dsArticles. Probably ObjectDataSource if you're using an
IEnumerable type list.

If you're just starting out with .NET 2.0, you probably want to check
out List(of T)...it could make creating your IEnumerable list MUCH
easier.
 
Hmmmm... But how can I bind my Page with it?

I'm doing this:
<%@ Page Inherits="AqDHome.HomePage" %>
<html>
<head></head>
<body>
<form runat="server">
<asp:ObjectDataSource runat="server" Id="PageSource"
SelectMethod="GetPage"
TypeName="AqDHome.HomePage"/>
<asp:FormView runat="server" Id="MyFormView"
DataSourceId="PageSource">
<ItemTemplate>
<asp:TextBox runat="server" Id="MyLabel"
Text='<%#Bind("MyName")%>'/>
<asp:Button runat="server" Id="MyButton" Text="Press"/>
</ItemTemplate>
</asp:FormView>
</form>
</body>
</html>

I have a property "MyName" in the AqDHome.HomePage class, but it seems
ASP.NET recreates the page whenever I call DataBind(), instead of
obtaining the page instance from GetPage (which simply returns "this")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top