afroblanca
Programmer
I'm wanting to leverage the GridView control. However, I don't want to add a DataSource control to my page in the VS .NET designer, because I do not like having data access layer information in the .ASPX.
So this is what I'm trying to do - create my SqlDataSource in a .CS file, and bind it to a GridView in the codebehind. However, it seems like MS really does not want me to do it this way.
My biggest problem has been deletion of rows. What I would really like to do is implement my own event handler for deletion. While it is possible to implement an event handler using the RowCommand event, there doesn't seem to be any way to remove the row from the actual table! GridView.Rows has no Delete() method, and GridView.DeleteRow() just calls the RowDeleting event, which is really no help at all.
So I thought, "Ok, I'll try it the other way. I won't try to implement my own event handler. I'll use the built-in event handlers for row deletion." No luck there either. This is the weird part - If I create the DataSource and wire it up to my GridView in the VS Designer, everything works just fine. HOWEVER, If I create my DataSource and wire it up to my GridView in a .CS, I get the error: "The GridView 'gvSites' fired event RowDeleting which wasn't handled." How come when you create the DataSource in the VS .NET designer, the event is automatically handled?
To be honest, all I really need from the GridView is the table formatting, paging, and sorting. The rest of the bells and whistles I could really do without. I've considered using a DataGrid, but from what I've read, DataGrids have been deprecated, so using them would be unwise.
Has anybody else had any success with implementing GridViews in a way that doesn't require data access layer information to be in the .ASPX? Can you point me to any good articles on the subject? Having data access layer info in the .ASPX offends my sensibilities in ways that I can't even properly explain. Am I correct in thinking this way, or am I being silly and pigheaded?
So this is what I'm trying to do - create my SqlDataSource in a .CS file, and bind it to a GridView in the codebehind. However, it seems like MS really does not want me to do it this way.
My biggest problem has been deletion of rows. What I would really like to do is implement my own event handler for deletion. While it is possible to implement an event handler using the RowCommand event, there doesn't seem to be any way to remove the row from the actual table! GridView.Rows has no Delete() method, and GridView.DeleteRow() just calls the RowDeleting event, which is really no help at all.
So I thought, "Ok, I'll try it the other way. I won't try to implement my own event handler. I'll use the built-in event handlers for row deletion." No luck there either. This is the weird part - If I create the DataSource and wire it up to my GridView in the VS Designer, everything works just fine. HOWEVER, If I create my DataSource and wire it up to my GridView in a .CS, I get the error: "The GridView 'gvSites' fired event RowDeleting which wasn't handled." How come when you create the DataSource in the VS .NET designer, the event is automatically handled?
To be honest, all I really need from the GridView is the table formatting, paging, and sorting. The rest of the bells and whistles I could really do without. I've considered using a DataGrid, but from what I've read, DataGrids have been deprecated, so using them would be unwise.
Has anybody else had any success with implementing GridViews in a way that doesn't require data access layer information to be in the .ASPX? Can you point me to any good articles on the subject? Having data access layer info in the .ASPX offends my sensibilities in ways that I can't even properly explain. Am I correct in thinking this way, or am I being silly and pigheaded?