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.

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.


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:
suppose that your 2nd field in the database is name and you want to display that in
Finally when you populate all your textboxes you could call the update method of that table on the button click event..