I have a template column that is a label. When the rowadding event is fired I can get all the other fields that are bound except my template columns. The e.Values does not have it. I do not know how to get my value server side. Please help.
I can do this on RowUpdating, but it does not work on RowAdding
drMedication("Medication_ID") = CType(e.Row.Items(3).FindControl("MedicationID"), Web.UI.WebControls.Label).Text '3
There are times when I need to have an AddRow in a data grid. To get the addRow, using a SQL data source, I've added a row in the stored procedure, using a union, and setting the ID of the row to -1.
then on the Row Update stored procedure, I check to see if the Id is -1, and if so, perform an insert, otherwise I'll update the current row.
This way a new row is never created on the sql server, and doesn't have to be deleted if the user cancels the operation.
If you would like an example, contact me offline
chuck.snyder@gmail.com
Hi baileyjames,
Please feel free to contact me if you have any further questions regarding this matter.
Thank you for your reply.
You can add the new row in your datasource in the RowAdding handler, and subsequently access the templated controls of the newly added row in the InitializeRow handler. I am attaching a sample illustrating such a scenario (a datatable has been used in this case for simplicity).
Please do not hesitate to contact me if you have any questions.
Ok, So do my insert in the IntializeRow event instead? Can I access all the bound grid values from there too? Any chance you have a small code snippit? Thanks.
I tried to code this and I'm using server side objects to retrieve and save data. So there is noSQLDataSource object that gets used. Obviously, the InitializeRow event is not triggered when I save to my object server side.
I find it hard to believe when you insert a new row and save it server side you cannot get to the values in template column fields...
Thank you for posting in the community.
When manually handling the row addition in WebDataGrid, the templated controls are not yet instantiated at the RowAdding stage (as opposed to the RowUpdating stage when the row object is fully accessible). After a row has been added to the datasource the InitializeRow event is fired again for each row. I suggest that you handle this event in order to access and modify your templated controls.
Please let me know if this helps.