Skip to content

Commit 08d9c4a

Browse files
committed
Added 1 section and 1 note for cases in tickets
1 parent eee94cf commit 08d9c4a

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

controls/grid/defining-structure/creating-a-radgrid-programmatically.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ This help article describes two options for creating a **RadGrid** instance dyna
1818

1919
* You can create the **RadGrid** entirely in the code-behind.
2020

21+
>Note
22+
This article demonstrates how to create and configure the RadGrid control programmatically on the code-behind, given that the data source structure will remain the same. If you want to dynamically change the columns of the grid depending on user selection or some dynamic condition (remove or add columns with different DataFields than the initial loaded structure), this might mess up the ViewState. For this scenario, please refer to the next [Changing the Grid Structure Dynamically on Postback]({%grid/defining-structure/changing-the-grid-structure-dynamically-on-postback%}) article.
23+
2124
When defining the structure of a hierarchical grid (by either method), you should follow these rules:
2225

2326
1. Create the **GridTableView** objects for every detail table. You do not need to create an object for the **MasterTableView** of the grid, as this is created automatically when the **RadGrid** itself is created.
@@ -55,19 +58,19 @@ To define the structure of a **RadGrid** control that is declared in the ASPX pa
5558

5659
````ASP.NET
5760
<telerik:RadGrid RenderMode="Lightweight" ID="RadGrid1" runat="server" />
58-
<asp:SqlDataSource ID="SqlDataSource1"
61+
<asp:SqlDataSource ID="SqlDataSource1"
5962
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
6063
ProviderName="System.Data.SqlClient"
6164
SelectCommand="SELECT * FROM Customers" runat="server"></asp:SqlDataSource>
62-
<asp:SqlDataSource ID="SqlDataSource2"
65+
<asp:SqlDataSource ID="SqlDataSource2"
6366
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
6467
ProviderName="System.Data.SqlClient"
6568
SelectCommand="SELECT * FROM Orders Where CustomerID = @CustomerID" runat="server">
6669
<SelectParameters>
6770
<asp:SessionParameter Name="CustomerID" SessionField="CustomerID" Type="string" />
6871
</SelectParameters>
6972
</asp:SqlDataSource>
70-
<asp:SqlDataSource ID="SqlDataSource3"
73+
<asp:SqlDataSource ID="SqlDataSource3"
7174
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
7275
ProviderName="System.Data.SqlClient"
7376
SelectCommand="SELECT * FROM [Order Details] where OrderID = @OrderID" runat="server">
@@ -245,11 +248,11 @@ When generating a grid in the **Page_Init** event handler, grid columns should b
245248

246249
````ASP.NET
247250
<asp:PlaceHolder ID="PlaceHolder1" runat="server" />
248-
<asp:SqlDataSource ID="SqlDataSource4"
251+
<asp:SqlDataSource ID="SqlDataSource4"
249252
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
250253
ProviderName="System.Data.SqlClient"
251254
SelectCommand="SELECT * FROM Customers" runat="server"></asp:SqlDataSource>
252-
<asp:SqlDataSource ID="SqlDataSource5"
255+
<asp:SqlDataSource ID="SqlDataSource5"
253256
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
254257
ProviderName="System.Data.SqlClient"
255258
SelectCommand="SELECT * FROM Orders Where CustomerID = @CustomerID" runat="server">

controls/grid/hierarchical-grid-types-and-load-modes/what-you-should-know.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ The new expand-all functionality supports all hierarchy load modes.
3838

3939
When you have grouping and hierarchy combined in a common table view, the visibility of the hierarchy expand-all button depends on whether the expand-all button for the last group level is expanded/visible.
4040

41+
## Controlling Expanded State
42+
43+
By default, the items in a hierarchical RadGrid are collapsed. In order to expand them automatically, you can use the **HierarchyDefaultExpanded** property. If the hierarchy structure contains several levels, the property should be set for every GridTableView instance separately.
44+
````ASP.NET
45+
<MasterTableView HierarchyDefaultExpanded="true">
46+
````
47+
48+
Since Q3 2013 version, RadGrid also provides the convenient **RetainExpandStateOnRebind** property. When you enable it, the expanded state of the parent items will be preserved automatically on rebinding actions like Paging, Editing, etc.
49+
4150
## See Also
4251

4352
* [Hierarchical data-binding using declarative relations]({%slug grid/hierarchical-grid-types-and-load-modes/hierarchical-data-binding-using-declarative-relations%})

0 commit comments

Comments
 (0)