I am making a page which allows the user to edit a specific row based on the querystring value. What is the best way to load data into the textboxes and to reflect the changes back to the database.

Example:
Request -> example.com/editpage.aspx?id=123

The page should display data from row with id=123 into a couple of textboxes. Then the user can edit those textboxes and press save. The new values of the textboxes should be saved back to the database in row with id=123.

I have already achieved this functionality but with lots of code and manually connecting to the database with , SqlConnection, DataSet and DataAdapter classes. I want to know if there is a better way of doing the same.

Thanks

Recommended Answers

All 2 Replies

Unless you really need a custom solution, you can accomplish this with the use of a simple "DetailsView" control.

I assume you are using Visual Studio. If so, drag a DetailsView control and configure it with the wizard by attaching a data source and configure the data source to be dependent on the querystring for the WHERE clause.

With the Detailsview control, you can enable the editing features. If you to customize the fields in the control, you can by converting the fields to a template view.

create a stored procedure to select the row where id= [your id in the Querystring]
Then you could call the value already saved in the database by that stored procedure..
Suppose you have this dataset named ds.
Dataset ds=new Dataset();
Now you have your id in the querystring. Now populate the datasource as follows:
ds.Datasource=objTable.YourSelectStoredProcedure();
suppose that your 2nd field in the database is name and you want to display that in
textbox1..
textbox1.text=objTable.YourSelectStoredProcedure().Tables[0].rows[0].Itemarray[1].toString();
Finally when you populate all your textboxes you could call the update method of that table on the button click event..

Regards.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.