The Gridview control in ASP.NET provides updating capabilities when a开发者_运维知识库ssigning 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?
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.
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
精彩评论