When I dynamically instantiate a RadGrid server side and insert it into a placeholder control I have no problems. If I create the same RadGrid with identical properties declaratively, I get the error: "Error: Sys.InvalidOperationException: A control is already associated with the element.". If I remove the AllowScroll property from the declarative RadGrid, the error goes away, but this isn't what I'm looking for. Since I will be reusing the same grid over several pages I created a user control that wraps the RadGrid, but I am still getting the error. Leaving out AllowScroll removes the error but, again, this isn't what I need. I tried adding the AllowScroll property in the pre-render event, but I get the same error. I can't figure out how the same grid created dynamically works when creating it declaratively doesn't.
Here's the dynamic version (c#):
RadGrid grid = new RadGrid();
grid.ID = "GridName";
grid.Skin = SkinName;
grid.CssClass = "gridCss";
grid.AllowMultiRowSelection = true;
grid.MasterTableView.HeaderStyle.Wrap = false;
grid.MasterTableView.HeaderStyle.Height = Unit.Pixel(50);
grid.MasterTableView.AutoGenerateColumns = true;
grid.ClientSettings.Scrolling.AllowScroll = true;
grid.ClientSettings.Scrolling.UseStaticHeaders = true;
grid.ClientSettings.Selecting.AllowRowSelect = true;
grid.ClientSettings.AllowKeyboardNavigation = true;
and here's the declarative version:
<telerik:RadGrid runat="server" ID="GridName" AllowMultiRowSelection="true" Skin="SkinName">
<ClientSettings AllowKeyboardNavigation="true" KeyboardNavigationSettings-AllowSubmitOnEnter="false">
<Selecting AllowRowSelect="true" />
<Scrolling AllowScroll="true" UseStaticHeaders="true" />
</ClientSettings>
<MasterTableView HeaderStyle-Wrap="true" HeaderStyle-Height="50px">
</MasterTableView>
</telerik:RadGrid>
Here's the dynamic version (c#):
RadGrid grid = new RadGrid();
grid.ID = "GridName";
grid.Skin = SkinName;
grid.CssClass = "gridCss";
grid.AllowMultiRowSelection = true;
grid.MasterTableView.HeaderStyle.Wrap = false;
grid.MasterTableView.HeaderStyle.Height = Unit.Pixel(50);
grid.MasterTableView.AutoGenerateColumns = true;
grid.ClientSettings.Scrolling.AllowScroll = true;
grid.ClientSettings.Scrolling.UseStaticHeaders = true;
grid.ClientSettings.Selecting.AllowRowSelect = true;
grid.ClientSettings.AllowKeyboardNavigation = true;
and here's the declarative version:
<telerik:RadGrid runat="server" ID="GridName" AllowMultiRowSelection="true" Skin="SkinName">
<ClientSettings AllowKeyboardNavigation="true" KeyboardNavigationSettings-AllowSubmitOnEnter="false">
<Selecting AllowRowSelect="true" />
<Scrolling AllowScroll="true" UseStaticHeaders="true" />
</ClientSettings>
<MasterTableView HeaderStyle-Wrap="true" HeaderStyle-Height="50px">
</MasterTableView>
</telerik:RadGrid>