The wonders of data binding in ASP.NET v2

One of the things that really got me excited about .NET v2 in early 2004 was the more declarative approach to coding ASP.NET pages. I like the idea of having a solid class library and then using as little code as possible in the actual page to get things done. The basic SqlDataSource in combination with various UI controls are great examples, but these barely scratch the surface of the cool things you can do.

The magic really starts with the DataSourceControl and  DataSourceView controls. Check out the code samples there. They really show how simple it is to roll this stuff yourself. It frees you of having to mess around with a ton of code and business objects manipulated in page code.

It's not all fun and games all of the time, mind you. It's still not easy to put a DropDownList in a GridView, populate and set its selection, and do it all correctly in the event structure for an edit. In one recent prototype I built, I actually had event handlers output to trace, for rows, the drop downs and the grid itself trying to figure out how to get it all to work. I think I got there, but it wasn't easy.

Doing custom ITemplate controls is a lot of fun too. You know how it is. Repeaters don't do enough, GridViews and DataGrids do too much. But roll your own template-based control, now that's alright! I've got a couple I wrote for the next POP Forums, because I wanted it to be as easy as possible to roll the UI the way it makes the most sense, including the insertion of ads. I'm really pleased with it.

I will post some code, hopefully soon. Crazy busy lately, but will get it up there eventually. 

2 Comments

  • I disagree with your assessment entirely. You're way over-thinking this stuff. I have no problem updating data as needed. I wrote this just the other day in my DataSourceView derived class...

    protected override int ExecuteInsert(IDictionary values)
    {
    Forum f = new Forum();
    if (values["CategoryID"] != null)
    f.CategoryID = Convert.ToInt32(values["CategoryID"]);
    if (values["Description"] != null)
    f.Description = values["Description"].ToString();
    ...
    f.Update();
    ...

  • I don't know which part you refer to when you say "over-thinking", but as far as your example goes:
    Where would you use your derived DataSourceView other than in your own DataSourceControl which you also have to implement.
    Furthermore, your solution is specific, my is generic. It can handle just any object while yours is targeted at specific type: Forum.

Comments have been disabled for this content.