DataBinding a single record

  • Thread starter Peter Morris [Droopy Eyes Software]
  • 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
 
R

RadekP

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
 
P

Peter Morris [Droopy Eyes Software]

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
 
R

RadekP

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
 

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

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top