DataBinding a single record

  • Thread starter Thread starter Peter Morris [Droopy Eyes Software]
  • Start date Start date
P

Peter Morris [Droopy Eyes Software]

Hi all

When I bind to multiple records I use a DataList. This allows the
web-designer to add code like <%#DataBinder.Eval(Container.DataItem,
"Name")%>

Whenever I want to retrieve a single record from the DB for editing I also
want to allow the designer to use the same technique. At the moment I am
still using a DataList for the single row, but this seems like the wrong
thing to do. How should I be doing it?


--
Pete
=============
http://www.DroopyEyes.com - Delphi source code
Audio compression components, Fast Strings, DIB Controls

Read or write article on just about anything
http://www.HowToDoThings.com
 
Pete

Databinding one record to DataList is still fine, especially when you want
to take advantage of its editing capabilities. Its data source enumerator
will enumerate its internal templated control just once. You still have
options, though. For example when you wanted to databind one record to let's
say Label control you could use:

<%# DataBinder.Eval(yourDataSet, "YourTable.Rows[0].YourColumn" %>

or using default DataView:

<%# DataBinder.Eval(yourDataSet,
"Tables[YourTable].DefaultView.[0].YourColumn" %>

You could use same technique to data bind to TextBox and allow editing by
updating yourDataSet.Tables["YourTable"].Rows[0]["YourColumn"] value with
your data adapter.

Different approach would be to construct business model (components) so you
could bind its exposed public properties even directly:

<%# MyComponent.MyProperty %>

HTH

Radek
 
Thanks :-)

RadekP said:
Pete

Databinding one record to DataList is still fine, especially when you want
to take advantage of its editing capabilities. Its data source enumerator
will enumerate its internal templated control just once. You still have
options, though. For example when you wanted to databind one record to let's
say Label control you could use:

<%# DataBinder.Eval(yourDataSet, "YourTable.Rows[0].YourColumn" %>

or using default DataView:

<%# DataBinder.Eval(yourDataSet,
"Tables[YourTable].DefaultView.[0].YourColumn" %>

You could use same technique to data bind to TextBox and allow editing by
updating yourDataSet.Tables["YourTable"].Rows[0]["YourColumn"] value with
your data adapter.

Different approach would be to construct business model (components) so you
could bind its exposed public properties even directly:

<%# MyComponent.MyProperty %>

HTH

Radek

Peter Morris said:
Hi all

When I bind to multiple records I use a DataList. This allows the
web-designer to add code like <%#DataBinder.Eval(Container.DataItem,
"Name")%>

Whenever I want to retrieve a single record from the DB for editing I also
want to allow the designer to use the same technique. At the moment I am
still using a DataList for the single row, but this seems like the wrong
thing to do. How should I be doing it?


--
Pete
=============
http://www.DroopyEyes.com - Delphi source code
Audio compression components, Fast Strings, DIB Controls

Read or write article on just about anything
http://www.HowToDoThings.com
 
FYI .. The new upcoming edition of ASP.NET 2.0 ("Whidbey") does have a
special, neat control for databinding one record with full editing/inserting
capability - "DetailsView" ..

Radek

Peter Morris said:
Thanks :-)

RadekP said:
Pete

Databinding one record to DataList is still fine, especially when you want
to take advantage of its editing capabilities. Its data source enumerator
will enumerate its internal templated control just once. You still have
options, though. For example when you wanted to databind one record to let's
say Label control you could use:

<%# DataBinder.Eval(yourDataSet, "YourTable.Rows[0].YourColumn" %>

or using default DataView:

<%# DataBinder.Eval(yourDataSet,
"Tables[YourTable].DefaultView.[0].YourColumn" %>

You could use same technique to data bind to TextBox and allow editing by
updating yourDataSet.Tables["YourTable"].Rows[0]["YourColumn"] value with
your data adapter.

Different approach would be to construct business model (components) so you
could bind its exposed public properties even directly:

<%# MyComponent.MyProperty %>

HTH

Radek

Peter Morris said:
Hi all

When I bind to multiple records I use a DataList. This allows the
web-designer to add code like <%#DataBinder.Eval(Container.DataItem,
"Name")%>

Whenever I want to retrieve a single record from the DB for editing I also
want to allow the designer to use the same technique. At the moment I am
still using a DataList for the single row, but this seems like the wrong
thing to do. How should I be doing it?


--
Pete
=============
http://www.DroopyEyes.com - Delphi source code
Audio compression components, Fast Strings, DIB Controls

Read or write article on just about anything
http://www.HowToDoThings.com
 
Back
Top