473,385 Members | 1,372 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

ASP.NET(C#) Storing changes to a database

Hi folks,

Although I'm an experienced programmer, I'm new to ASP and relatively new to web programming, so I hope you'll be patient with my questions.

I'm working on a project using ASP.NET and C# for the server side code. I've written code to retrieve data from a database and put it into a dynamic html table for the user to view and edit. Works great. Now I want to save those changes and that's where I'm unsure how best to proceed.

I have a "Save Changes" button on the page that I want the user to use to indicate that they've finished making changes to the data and to store it back to the database. My initial intention is to have the click of this button call my server side C# code and it will scan the table, find what changed (if possible) and store it. If it can't necessarily tell what changed, that's okay as I can store all records regardless as it's only about 200 records.

First of all, is this really the way to do it? Or is there a smarter way to store changes back to the database?

Assuming my design is adequate, how is my server side code able to get to the records in this table on the client?

Also, I'm thinking of storing a hidden "dirty bit" on the client side for each row that changes (via JavaScript) and the "Save Changes" will scan through the table for those that have the dirty bit set and only save those. Is this feasible? Again, is there a smarter way to handle this?

Thanks for any advice anyone can give. I'm learning a lot about the limitations of web programming and the tricks of having to pass information between client and server. It makes things a bit more challenging, to be sure.

Robert Porter
Apr 9 '08 #1
4 1709
nateraaaa
663 Expert 512MB
Instead of using an html table I would recommend using a datagrid (or Gridview if you are using .NET 2.0 or higher). This control gives you the ability to identify the row being updated in the ItemCommand event (RowCommand if using GridView).

Nathan
Apr 9 '08 #2
Plater
7,872 Expert 4TB
The GridView generates a dynamic html table for you. You can just give it an instance of the DataTable (or DataSet) object and it will populate for you.
A bonus of using the DataTable is that each row in there has a .RowState property that will tell you if anything has changed (you can then accept or reject changes). Which can be used to writeback data to database.
Apr 9 '08 #3
Thanks for the advice. I'd already spent a lot of time setting up the html table and it works, so I was hoping to avoid having to scrap that and do the GridView which I've just discovered. But the GridView certainly does seem the way to go. I've been experimenting with it (and having a few issues with my database connection, but that's another topic).

Is it possible to add a dynamically populated DropDownList in a GridView? I'd like to get a list of valid values from the database and add it to the GridView's DropDownList so the user has to choose one of those values.

Robert
Apr 9 '08 #4
nateraaaa
663 Expert 512MB
Yes you would use a TemplateColumn and place your drop down list in the TemplateColumn.

Here is a link to a tutorial that explains Gridview and common ways to utilize it.
http://www.asp.net/learn/data-access...ial-19-cs.aspx

Nathan
Apr 11 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Lester Moreno | last post by:
Hello all, Up to now C# have been an great experience but I found myself in a end of the road problem. Let say that you have two windows program running on a local network area. User1 and...
7
by: jsale | last post by:
I'm currently using ASP.NET with VS2003 and SQL Server 2003. The ASP.NET app i have made is running on IIS v6 and consists of a number of pages that allow the user to read information from the...
17
by: | last post by:
I have an app that retrieves data from an Access database. At the moment I have the SQL string as a Const in my app. I understand this is not best practice. I don't want the user to have access to...
2
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
3
by: Lucky_Syringe | last post by:
I wrote this script to display different files from a database and properly display them by their respective MIME types. I have two questions: the first is that it just so happens not to work, and...
0
by: shamirza | last post by:
· When was .NET announced? Bill Gates delivered a keynote at Forum 2000, held June 22, 2000, outlining the .NET 'vision'. The July 2000 PDC had a number of sessions on .NET technology, and...
0
by: shamirza | last post by:
· What is view state and use of it? The current property settings of an ASP.NET page and those of any ASP.NET server controls contained within the page. ASP.NET can detect when a form is requested...
10
by: LionsDome | last post by:
Hello, I have a vb.net page which a bunch of checkboxes. A user can select a checkbox(s) and hit the submit button to store those values in a SQL Server table. This works fine with no problem...
5
by: jehugaleahsa | last post by:
Hello: What is the point of using a DataTable in ASP .NET? We are unsure how you can use them without 1) rebuilding them every postback, or 2) taking up precious memory. We are not sure how to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.