Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 10th, 2010, 08:49 PM
Authorized User
Points: 77, Level: 1
Points: 77, Level: 1 Points: 77, Level: 1 Points: 77, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2010
Posts: 15
Thanks: 8
Thanked 0 Times in 0 Posts
Smile DB

Hi there all...

On page 472-473, there are these 2 quotes:

" So, when you click Update after making changes to the review in the page, the DetailsView collects all the bound data from the form (the Title, Summary, Body, GenreId, and whether the item is authorized) and then sends it to the SqlDataSource control that has parameters set up for each of the relevant columns of the Review table"
-----------------------------------------------------------------
"As you saw earlier, ItemInserting fires right before the InsertCommand is sent to the database. This is a perfect location to supply (default) values for the columns in your table that have no corresponding control in the user interface, as is the case with the UpdateDateTime. This code simply sets the
UpdateDateTime value to today’s date and time. This value is then sent to the database where it is used to assign a value to the Review table’s UpdateDateTime column."


Now, in relation to the quotes above, what I don't get is why do we need the Bind syntax?
In the Genre.aspx page, when user clicks on update, the GridView collects the data from the form - includes the textboxes, and forward them to the DataSource control(as elaborated on page 441-442).
In this case, there is no use in the Bind syntax, and yet it's working fine..
How is this possible?

10x...
Reply With Quote
  #2 (permalink)  
Old November 11th, 2010, 04:28 AM
Authorized User
 
Join Date: Oct 2009
Posts: 22
Thanks: 2
Thanked 10 Times in 7 Posts
Default

The reason updating is working in the page that you specified is because you are using BoundField as the column and field types in your GridView and DetailsView on that page.

Bind comes into play when you want to create your own template by using the TemplateField column or field type. This is where you need to use Bind to get two-way data binding. As you progress more into this chapter, you will see examples of the use of the Bind. You will start using it in the AddEditReview.aspx page.

With the GridView and DetailsView there are alternative column or field types that will allow you to perform two-way databinding without the need for Bind, but sometimes you want more control over the output and need to use the TemplateField; this is where the Bind comes into play. Also, note that you have to use Bind when working with the DataList and ListView, because you don't have the additional field types when using those two controls. You have to work with template fields.
Reply With Quote
The Following User Says Thank You to walbalooshi For This Useful Post:
Imar (November 11th, 2010)
  #3 (permalink)  
Old November 11th, 2010, 04:39 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi stormage,

The GridView uses Bind as well, but by default handles this internally. To see what I mean, take the code example from the bottom of page 440 (the GridView) and place it in an ASP.NET page. You can see that the columns exist of BoundFields. For example, the Name field looks like this:
Code:
 
<asp:BoundField DataField=”Name” HeaderText=”Name” SortExpression=”Name” />
The BoundField acts as a wrapper around the various templates (such as the item, insert and edit templates). Additionally, this control is able to keep track of the column it's associated with without explicit Bind syntax.

Next switch the page into Design View, open the GridView's Smart Tasks panel and choose Edit Columns. In the Selected Fields drop down, click Name and then click the blue Convert This Field Into A TemplateField link. You won't see a difference in Design View. Next, switch back to Markup View and look at the code for the Name field:

Code:
<asp:TemplateField HeaderText="Name" SortExpression="Name">
 <EditItemTemplate>
  <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Name") %>'></asp:TextBox>
 </EditItemTemplate>
 <ItemTemplate>
  <asp:Label ID="Label1" runat="server" Text='<%# Bind("Name") %>'></asp:Label>
 </ItemTemplate>
</asp:TemplateField>
Notice how it now uses Bind to hook up the various columns to their respective controls.

So, the GridView uses a binding concept as well; it's just that by default it hides this from you using BoundField controls if you have no need to alter the appearance of the columns (which you can do once you've converted them to templates).

Does this help?

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
The Following User Says Thank You to Imar For This Useful Post:
stormage (November 11th, 2010)
  #4 (permalink)  
Old November 11th, 2010, 04:41 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi walbalooshi,

Thanks for your message; I was typing mine when you submitted yours, so I am more or less just repeating you ;-)

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
The Following 2 Users Say Thank You to Imar For This Useful Post:
stormage (November 11th, 2010), walbalooshi (November 11th, 2010)
  #5 (permalink)  
Old November 11th, 2010, 05:37 AM
Authorized User
 
Join Date: Oct 2009
Posts: 22
Thanks: 2
Thanked 10 Times in 7 Posts
Default

Hi Imar,

You usually answer questions so quickly that I was surprised I saw this one still unanswered. I should have known that you would be lurking in the background answering the same question :)

Keep up the great work.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How To: Use hosted mySQL DB instead of local SQL express DB? allan_ravn BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 4 April 14th, 2009 03:09 PM
Finding the DB Sailor.mdb of Beginning ASP DB book anna Classic ASP Databases 2 August 5th, 2006 01:13 PM
Converting Access DB to Online DB eyal8r Access 5 December 6th, 2004 05:22 AM
access db to sql server db mikersantiago Classic ASP Basics 4 November 16th, 2004 03:33 AM
Synchronizing web db with our master db sunny25 Classic ASP Basics 0 October 17th, 2003 09:16 AM



All times are GMT -4. The time now is 08:04 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.