Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: Data binding in ASP.Net - This should be simple


Message #1 by "Carl Schneider" <cschneider@i...> on Tue, 25 Sep 2001 21:27:08
Hey all,



I'm missing something conceptually... How do I bind ASP Server controls to 

a record. Quickstart mentions simple databinding and then jumps to 

connecting databases to grids and such. It's all great stuff but I just 

want to select a record and see an editable form. Then submit my updates. 



If some body could shed light on this for me or shoot me a link to some 

sample source it sure would help. 



Also...



I had a hell of a time finding the object models and reference info on 

MSDN. Still cant find an list of global.asax and page events in the 

library. Any advice there would rock.



Thanks,



Carl Schneider
Message #2 by Tim Heuer <TimH@i...> on Tue, 25 Sep 2001 14:28:40 -0700
Carl,



First, regarding the reference material...I'd suggest the Professional

ASP.NET book from WROX...great resource to have during the "getting used to

.NET" phases we all seem to be going through.



Second, regarding binding to data:



This would involve understanding a bit more about your data, what the form

looks like etc.  But let's say we have a form with 3 fields: first name,

last name, phone and I wanted to retrieve data from my db and populate these

fields.  Assume you have the form with asp:textboxes being used and also

assume your database query returns only one record (the one you are

seeking), it may look something like this:



SqlConnection cn = new SqlConnection("");

SqlDataAdapter da = new SqlDataAdapter("select * from authors where

id=2",cn);

DataSet ds;



da.Fill(ds);



DataRow dr = ds.Tables[0].Rows[0];

txtFirstName.Text = dr["first_name"].ToString();

txtLastName.Text = dr["lasst_name"].ToString();

txtPhone.Text = dr["phone"].ToString();



Which would populate the form.  To update you'd want to capture the click

event, read the values and send the appropriate update command.



As I mentioned, this may seem rather useless as there is not a lot of

context, but unlike the DataGrids, DataLists, there is no easy way to

DataBind a form mixed with dropdowns, textboxes, etc. to a single record.



Tim



-----Original Message-----

From: Carl Schneider [mailto:cschneider@i...] 

Sent: Tuesday, September 25, 2001 2:27 PM

To: ASP+

Subject: [aspx] Data binding in ASP.Net - This should be simple





Hey all,



I'm missing something conceptually... How do I bind ASP Server controls to 

a record. Quickstart mentions simple databinding and then jumps to 

connecting databases to grids and such. It's all great stuff but I just 

want to select a record and see an editable form. Then submit my updates. 



If some body could shed light on this for me or shoot me a link to some 

sample source it sure would help. 



Also...



I had a hell of a time finding the object models and reference info on 

MSDN. Still cant find an list of global.asax and page events in the 

library. Any advice there would rock.



Thanks,



Carl Schneider







  Return to Index