Editing tables with ASP.Net - Quick 'n Dirty
Asked Answered
D

4

7

I have need to provide a way for users to edit tables in ASP.Net. The tables are simple (no master/detail relationships), but there are likely to be a lot of them. What's the quickest/simplest way to provide a view/edit interface to a table, even considering commercial options (but not Iron Speed Designer. That thing is ridiculously expensive for what I need)?

In its most simple/ideal configuration, I'd want to point a control at a table and be done. I've looked at a few ORM solutions, but they all try to be a swiss army knife which just piles on the complexity and tend to be beasts unto themselves.

Is there something that is crazy simple that can help me here? Or should I just dive into SubSonic or something similar?

Dessau answered 4/6, 2010 at 13:52 Comment(2)
Looks like Dynamic Data is a winner, but does anyone have any good insights into SubSonic vs. Dynamic Data? SubSonic is Haack's project, right? So both are from Microsoft now? Can anyone give an elevator pitch on the differences? Maybe even a quick demo similar the one linked by Graham Clark below? This sentence added so as to not have my entire comment made up of questions.Dessau
SubSonic is not Haack's project, nor Microsoft's, but I believe Phil Haack did contribute to SubSonic. SubSonic is an ORM and it sounds like you don't want an ORM.Assemble
D
6

After some research, the quickest thing I found turns out to be just using linq to sql with a GridView. I was looking for a solution that can easily integrate into existing pages. Without the benefit of auto-scaffolding and generated pages, Dynamic Data kinda misses the mark. 99% of what I wanted was to avoid getting into writing SQL statements and handling the UpdateCommands manually.

Here are the steps I wrote up for my own personal reference. It relies heavily on the designers, but for what I need, this is perfect:

  1. New project (or existing project)
  2. Add LinqToSqlClass file to project
  3. Add Relevant tables from datasource to design surface (use server explorer)
  4. Build project (so that datacontext class will get generated)
  5. Go to aspx page
  6. Drag a linqdatasource object from toolbox.
  7. Configure datasource (make sure to enable update if necessary)
  8. Drag a gridview from toolbox
  9. Set datasource to linqdatasource object you just created
  10. Customize columns if necessary (ie, set readonly property on non-editable columns, hide non-relevant columns.)

As far as dynamic data is concerned, the documentation is currently lacking. There's a LOT of stuff that references earlier versions that doesn't work quite the same now. I watched the videos here and followed the steps here, but ultimately ran into problems when I tried hiding non-editable columns. The update statement generated by linq didn't reference the primary key and I got the Row not found or changed error. I gave up and used the solution above.

Hope this helps someone else in the future!

Dessau answered 9/6, 2010 at 15:17 Comment(0)
M
5

Dynamic Data is a very easy way to edit database tables via ASP.Net. I had absolutely no knowledge of it, but I set up a website to edit a small database in literally 5 minutes, using one of Scott Guthrie's blog posts. It handled the simple foreign key relationships I had as well.

Monochromatic answered 4/6, 2010 at 14:2 Comment(1)
Thanks for the link. It looks very near to what I want. Will look into it further. I <3 teh Gu.Dessau
B
4

Try DynamicData from microsoft, built in to asp.net 4, avalable as download for earlier versions.

Belsky answered 4/6, 2010 at 13:54 Comment(0)
B
1

Here's a tutorial on how to do it using a standard ASP.NET Gridview.

Bridgettebridgewater answered 4/6, 2010 at 13:55 Comment(3)
That is exactly what I've been doing for years that makes me want to poke my eyes out with a sharp stick...Dessau
Please mark your selected answer as the answer (using the green checkmark). Downvoting other answers that aren't the optimal one is not how StackOverflow works. (i.e. This answer gets the job done).Bridgettebridgewater
I understand how SO works, and I appreciate your input. It may get the job done, but isn't at all what I was looking for and wasn't useful in this case. (when did the 24 hour limit on accepting answers get removed?)Dessau

© 2022 - 2024 — McMap. All rights reserved.