views:

59

answers:

2

The Gridview control in ASP.NET provides updating capabilities when assigning a SqlDataSource control to the Gridview's DataSourceID, however when programmatically assigning a code level SqlDataSource to DataSource, the built-in updating capabilities go away and you are forced to roll your own. Why? What is the difference here, since all we're doing is referring to the SqlDataSource directly, instead of by ID? Why can the GridView still not take advantage of the SqlDataSource UpdateCommand?

+1  A: 

Well, the first case, it has 2 native controls. Web and Data. You can perform RAD via VS.NET via their visual and configuration tools. MS ensure that the framework can allow such visual controls to data controls coupling in the aspect of CRUD automatically.

Second case, when you have your own SqlDataSource which is not one of the data controls, you are on your own. That's how it is. I hope someone can tell us a solution for it too.

my 2 cents.

o.k.w
A: 

I've discovered that it's possible to programmatically create a SqlDataSource, give it an ID, and assign the properties as follows to allow the built in editing to be mapped properly:

gvData.DataSourceID = dataSource.ID
byte
@dxmio, so it behaves exactly the same per SqlDataSource DataControl? Cool if it does!
o.k.w
@o.k.w I don't understand your question - a programmatically crafted SqlDataSource is no different than one created with tags.
byte