Hi,
I am using Telerik controls version "2009.3.1103.20", visual studio 2008 and website project.
Now on one of my page, I have RadGrid and have "DetailTable" underneath "MasterTableView", so basically when I assign datasource to my master table, it displays option to "Expand\Collapse" and when I click on "Expand" arrow, it fires "OnDetailTableDataBind" event where I assign dataset to my detail table and it displays whatever number of rows I have in detail table.
So basically I have kind of master-detail view where I can expand\collapse items to view detail view.
Now on my "DetailTable", I have some rows which has some buttons and on click of those buttons, I am updating some values in my database and refreshing grid. The problem is that while binding grid again, grid is losing its state of already expanded rows and all the rows are in "Collapsed" state. What I want is after rebinding grid, it should keep expanded rows as it is. This is happening on postback always. Even If I use "Sorting" on my master table fields, it collapses all the rows but I want to show the expanded rows as it is whichever were expanded already by user, should stay expanded after postback.
Any suggestion how to achieve this?
Here is my RadGrid.
Here is what I tried to expand it back after postback but could not get it working, not sure why. Just pasting for reference which I tried. Please do let me know the best option to achieve this.
Thanks in advance,
I am using Telerik controls version "2009.3.1103.20", visual studio 2008 and website project.
Now on one of my page, I have RadGrid and have "DetailTable" underneath "MasterTableView", so basically when I assign datasource to my master table, it displays option to "Expand\Collapse" and when I click on "Expand" arrow, it fires "OnDetailTableDataBind" event where I assign dataset to my detail table and it displays whatever number of rows I have in detail table.
So basically I have kind of master-detail view where I can expand\collapse items to view detail view.
Now on my "DetailTable", I have some rows which has some buttons and on click of those buttons, I am updating some values in my database and refreshing grid. The problem is that while binding grid again, grid is losing its state of already expanded rows and all the rows are in "Collapsed" state. What I want is after rebinding grid, it should keep expanded rows as it is. This is happening on postback always. Even If I use "Sorting" on my master table fields, it collapses all the rows but I want to show the expanded rows as it is whichever were expanded already by user, should stay expanded after postback.
Any suggestion how to achieve this?
Here is my RadGrid.
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
AllowPaging
=
"true"
AllowSorting
=
"true"
AutoGenerateColumns
=
"False"
GridLines
=
"Both"
OnNeedDataSource
=
"RadGrid1_needdatasource"
OnItemDataBound
=
"RadGrid1_ItemDataBound"
OnDetailTableDataBind
=
"RadGrid1_DetailTableDataBind"
OnItemCreated
=
"RadGrid1_ItemCreated"
AllowMultiRowSelection
=
"true"
AllowFilteringByColumn
=
"true"
OnItemCommand
=
"RadGrid1_ItemCommand"
SelectedItemStyle-CssClass
=
"SelectedItem"
Skin
=
"Default"
>
<
PagerStyle
Mode
=
"NextPrevNumericAndAdvanced"
Position
=
"TopAndBottom"
AlwaysVisible
=
"true"
/>
<
ClientSettings
EnableRowHoverStyle
=
"true"
EnablePostBackOnRowClick
=
"true"
>
<
Selecting
AllowRowSelect
=
"true"
/>
</
ClientSettings
>
<
FooterStyle
BackColor
=
"LightBlue"
/>
<
MasterTableView
ShowHeadersWhenNoRecords
=
"true"
AllowFilteringByColumn
=
"true"
DataKeyNames
=
"RequestInfoID"
Name
=
"ApprovalsMaster"
>
<
DetailTables
>
<
telerik:GridTableView
DataKeyNames
=
"RequestInfoID"
Width
=
"80%"
Name
=
"ApprovalsDetail"
AllowPaging
=
"false"
runat
=
"server"
>
<
ParentTableRelation
>
<
telerik:GridRelationFields
DetailKeyField
=
"RequestInfoID"
MasterKeyField
=
"RequestInfoID"
/>
</
ParentTableRelation
>
<
Columns
>
<
telerik:GridBoundColumn
SortExpression
=
"ApprovalLevelID"
HeaderText
=
"ApprovalLevelID"
HeaderButtonType
=
"TextButton"
DataField
=
"ApprovalLevelID"
UniqueName
=
"ApprovalLevelID"
>
</
telerik:GridBoundColumn
>
<
telerik:GridTemplateColumn
HeaderText
=
"Approve"
UniqueName
=
"ApproveRequest"
AllowFiltering
=
"false"
>
<
ItemTemplate
>
<
asp:Button
runat
=
"server"
ID
=
"btnApproveRequest"
Text
=
"Approve"
CssClass
=
"ButtonCSS"
ToolTip
=
"Click here to Approve Request"
CausesValidation
=
"False"
OnClick
=
"btnApproveRequest_Click"
OnClientClick
=
"javascript:var agree= confirm('Are you sure you want to approve this Request? '); if(agree){ Page_BlockSubmit = false;buttonClicked_WithObj(this); return true; };else {return false;};"
CommandArgument='<%#
Eval ( "RequestInfoID").ToString()
+ ";" +
Eval ( "ApprovalLevelID").ToString()
%>' />
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
</
Columns
>
</
telerik:GridTableView
>
</
DetailTables
>
<
Columns
>
<
telerik:GridNumericColumn
DataField
=
"RequestInfoID"
HeaderText
=
"Request No."
SortExpression
=
"RequestInfoID"
DataType
=
"System.Int64"
FilterControlWidth
=
"40px"
>
</
telerik:GridNumericColumn
>
<
telerik:GridBoundColumn
DataField
=
"DepartmentName"
HeaderText
=
"Department"
SortExpression
=
"DepartmentName"
UniqueName
=
"DepartmentName"
>
</
telerik:GridBoundColumn
>
</
Columns
>
<
EditFormSettings
>
<
PopUpSettings
ScrollBars
=
"None"
/>
</
EditFormSettings
>
<
ExpandCollapseColumn
Resizable
=
"False"
Visible
=
"False"
>
<
HeaderStyle
/>
</
ExpandCollapseColumn
>
<
RowIndicatorColumn
Visible
=
"False"
>
<
HeaderStyle
/>
</
RowIndicatorColumn
>
</
MasterTableView
>
</
telerik:RadGrid
>
Here is what I tried to expand it back after postback but could not get it working, not sure why. Just pasting for reference which I tried. Please do let me know the best option to achieve this.
OnDataBound="RadGrid1_DataBound"
OnDataBinding="RadGrid1_DataBinding"
protected void RadGrid1_DataBound(object sender, EventArgs e)
{
LoadGroupsExpandedState(RadGrid1);
}
protected void RadGrid1_DataBinding(object sender, EventArgs e)
{
SaveGroupsExpandedState(RadGrid1);
}
private void SaveGroupsExpandedState(RadGrid grid)
{
GridItem[] groupItems = grid.MasterTableView.GetItems(GridItemType.GroupHeader);
if (groupItems.Length > 0)
{
List<
string
> collapsedIndexes = new List<
string
>();
foreach (GridItem item in groupItems)
{
if (!item.Expanded)
{
GridGroupHeaderItem groupHeader = (GridGroupHeaderItem)item;
collapsedIndexes.Add(groupHeader.DataCell.Text);
}
}
Session["groupExpandedState"] = collapsedIndexes;
}
}
private void LoadGroupsExpandedState(RadGrid grid)
{
List<
string
> collapsedIndexes = Session["groupExpandedState"] as List<
string
>;
if (collapsedIndexes != null)
{
foreach (GridItem item in grid.MasterTableView.GetItems(GridItemType.GroupHeader))
{
GridGroupHeaderItem groupHeader = (GridGroupHeaderItem)item;
if (collapsedIndexes.Contains(groupHeader.DataCell.Text))
{
item.Expanded = false;
}
}
}
}
Thanks in advance,