It appears there is some kind of issue with calling ClearDataSource on a postback and the presence of the "Multiple controls with the same ID error" being thrown when a Template control exists in the WebDataGrid.
I have a template column with a checkbox and if I use the ClearDataSource call before rebinding the WebDataGrid on a postback I get the "Multiple controls..." error presumably related to the checkbox. If I comment out the ClearDataSource my postback works just fine and I don't get the fatal error but then, even though I'm rebinding the WebDataGrid (with a refreshed object List<T> collection pulled from the db) on the postback, the OnInitializeRow event handler does not fire again - it will fire on the intiial page load and that's it - which also is a problem as I set some custom cell tooltips when the InitializeRow event is fired - seem's I'm darned if I do, and darned if I don't. Anyone have any thoughts.
We've been running into the same problem using v10.3 SR 2134.
To workaround the issue we've added the following extra WebDataGrid clearing logic (inside the 'doExtraClearingLogic' if block) to be executed only during the re-binds that were causing us to receive the multiple controls with the same ID errors.
grdSelectedHorse.Rows.Clear()grdSelectedHorse.ClearDataSource()If doExtraClearingLogic Then Dim templateControlContainer As PropertyInfo = grdSelectedHorse.GetType.GetProperty("TemplateContainerControl", Reflection.BindingFlags.GetProperty Or Reflection.BindingFlags.Instance Or Reflection.BindingFlags.NonPublic) DirectCast(templateControlContainer.GetValue(grdSelectedHorse, Nothing), Control).Controls.Clear()End IfgrdSelectedHorse.DataSource = listgrdSelectedHorse.DataBind()
Note: 'grdSelectedHorse' is our WebDataGrid & 'list' is a Generic.List of anonymous typed objects in our case
Hope this helps someone!
Hello,
Do you have this piece of code for c# please?
Thanks.