开发者

Editing tables with ASP.Net - Quick 'n Dirty

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 t开发者_开发百科hat is crazy simple that can help me here? Or should I just dive into SubSonic or something similar?


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!


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.


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜