I have a grid that is bound to a SQLDataSource that works perfect until I make one of the columns a template column and add a textbox to that column. It doesn't save the data entered into the textbox now. It doesn't appear that the grid_UpdateRow or the SqlDatasource_Updating is firing, but they were firing before I made this one column a template column.
I edited the DataBindings and bound the Text to the field it should be updating, but it isn't.
Any help is appreciated.
Thanks!
I think I'll just use the grid's built-in functionality. It works well...I just like the look of the textbox, but that's not a big deal since I'm not required to use the textboxes for this application.
Thanks for your advice.
Using the setup you've described, this is expected behavior.
When you make a column into a templated column, you could put any of a number of ASP.NET or HTML controls inside the cell template - some of which may have no relation to the cell's value. Addiitionally, the databinding syntax typically used to put a value into a control inside a templated cell item is one-way databinding, not two-way.
As a result, changes you make to your TextBox affect the TextBox only. The grid has no knowledge that anything was changed, and so does not raise any update-related events.
There are a couple of options available.
One way is to handle the server-side events of the control inside your item template, and use server-side code to update your underlying data. This is a good approach when you're using a DataSet or a custom business object, and is (in my experience) less useful when using a SqlDataSource, ObjectDataSource, or other data source control.
Another approach is to write JavaScript code for the controls in your item template, so that changing the input of the control changes the Value property of the corresponding WebGrid cell. This way, you can then depend on the grid's already-present updating functionality. This is likely the best approach in your case, since you're using a SqlDataSource.
My advice, if it's possible under your application's requirements, is to use the grid's built-in update functionality, and avoid using a templated column to provide a TextBox. You could use a Row Edit Template if you need something to appear as a TextBox for input purposes, as opposed to using the grid's normal built-in editing. I'd give similar advice for checkboxes used as input as well, since this is an input type that the grid can already handle.