Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Edit one record only 1

Status
Not open for further replies.

vwhite

Programmer
Oct 4, 2001
87
AU
I am new to programming in ASP.NET and I am currently trying to migrate an application from ASP to ASP.NET (1.1)

I am a litle stumped with this pretty basic question. It seems that all the web controls - datgrid, datalist, datarepeater are designed for displaying multiple records at a time and then editing them line by line.

I have a large table (with many child tables). I want to be able to select a record from this table(from say a drop down list), then display the fields for that record then update them and update back to the database for that single record.

What is the best way to go about this?

Many Thanks



....vwhite

"Benefit others. If you cannot benefit others then do them no harm"
- His Holiness Tenzin Gyatso, the 14th Dalai Lama
 
provide a link for the record that you want to update.

on clicking the link take the user to some other page (pass some id for recognition using query strings)...

Known is handfull, Unknown is worldfull
 
You might also consider setting up a dropbox/option list, etc, to populate yet a second dropdown/option list, etc. and so forth and then when finally reaching the last child table have it appear in an editible DataGrid (you might also consider using a DataSet (DataView) for updating records in the child table (obv. several approaches to a problem like this). vbkris's suggestion to open up the final recordset on an independent page is also a clean and user friendly way to approach this problem.
 
I have accomplished the drop down list and selecting the record no problem, but what I am confused about is what web control to use then to display and edit all the fields in this one record (ignoring the child records for now)

Do I need to use a heap of textboxes, checkboxes, dropdwns etc and then bind them all using the <% # databind.Eval(Dataset.Table(column)) # > function?

After I fill the dataset from the datadapter do I then have to bind each control e.g txtFirstName.DataBind, txtLastName.DataBind etc.

Another option I thought about is using a datarepeater but only filling it with one record. But I'm not sure how I would do the child tables in this case.

....vwhite

&quot;Benefit others. If you cannot benefit others then do them no harm&quot;
- His Holiness Tenzin Gyatso, the 14th Dalai Lama
 
You can use a datagrid, but it wouldn't make sense to go through the trouble for just one row. I have use textboxes in the past, and just bound the data to them.. Then I get the values from the textboxes and use the .text to construct an update statement.

Jim
 
When you say do Bind the data - is the method I described above correct then i.e. DataBind.Eval(Dataset.tables(column)) and then DataBind each textbox etc?

I was then going to use the Update command of the Data Adapter.

By the way what happens if more than one person is editing the record at the same time? Is the record locked in any way?

....vwhite

&quot;Benefit others. If you cannot benefit others then do them no harm&quot;
- His Holiness Tenzin Gyatso, the 14th Dalai Lama
 
I belive your way of doing it will work, however I don't do it that way. I set the databinding properties of the textbox and then call TextBox1.DataBind().

You can also use the dataadapter as well. What ever you are more comforatable with.

As far as locking is concerned, there is no locking mechanism in .NET or sql server. The row will only be locked for the time it takes for the Update to actually occur. So, one person's update can override another's update if they update in quick succession.
What I do to avoid that problem is to set a flag column in the table (a bit datatype). Once the user selects the row to be updated I set it to 1. If person 2 clicks the same row, I check the bit column and display an error if it is 1(being edited.) Then once the update is done, I reset the bit column back to 0.

Jim
 
thanks for all your help with this...

What do you mean by 'Set the databinding properties of the textbox' - I thought DataBind.Eval was doing that?

Vicky
 
I forgot to mention I am not using VS.NET - so I have to write the code manually. Hence probably my misunderstanding when you say 'Set the databinding properties of the textbox'.

Vicky
 
Just so you know I have gone down the path of setting the .text, selectedindex etc values manually instead of using the databinding.Eval as it started to get way to complex.

So I have ended up with lines like this

txtProjectNo.text = m_dsProject.Tables("CMA_PROJECTS_TBL").Rows(0)("LOCAL_PROJECT_NO")

ddlAwardedTo.SelectedIndex = ddlAwardedTo.Items.IndexOf(ddlAwardedTo.Items.FindByValue(m_dsProject.Tables("CMA_PROJECTS_TBL").Rows(0)("AWARDED_TO")))

- for every field and then datagrids etc for all the child tables.

Hope I have done the right thing.

Cheers again
Vicky.






 
That's the way I'd do it as well (doesn't mean it's right or wrong though as it's really just down to your preference).


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Vicky.. glad you have things going....Like ca8msm says it's down to preference. I just figure, I have VS as my IDE, I will let it do as much work for me as possible, so I can concentrate on other things...


good luck :)

Jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top