11 Answers, 1 is accepted
0

Shinu
Top achievements
Rank 2
answered on 04 Oct 2012, 03:36 AM
Hi Lasly,
Please check the following code snippet I tried to prevent the closing of group when the edit button is clicked.
ASPX:
C#:
Thanks,
Shinu.
Please check the following code snippet I tried to prevent the closing of group when the edit button is clicked.
ASPX:
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
OnNeedDataSource
=
"RadGrid1_NeedDataSource ShowGroupPanel="
True"
OnGroupsChanging
=
"RadGrid1_GroupsChanging"
OnItemCommand
=
"RadGrid1_ItemCommand"
AutoGenerateEditColumn
=
"true"
>
<
ClientSettings
AllowDragToGroup
=
"True"
></
ClientSettings
>
<
MasterTableView
GroupsDefaultExpanded
=
"false"
EditMode
=
"InPlace"
>
<
GroupByExpressions
>
<
telerik:GridGroupByExpression
>
<
GroupByFields
>
<
telerik:GridGroupByField
FieldName
=
"Group"
/>
</
GroupByFields
>
<
SelectFields
>
<
telerik:GridGroupByField
FieldName
=
"Group"
/>
</
SelectFields
>
</
telerik:GridGroupByExpression
>
</
GroupByExpressions
>
</
MasterTableView
>
</
telerik:RadGrid
>
C#:
public
Hashtable Groups
{
get
{
if
(ViewState[
"Groups"
] ==
null
)
{
Hashtable res =
new
Hashtable();
ViewState[
"Groups"
] = res;
return
res;
}
return
(Hashtable)ViewState[
"Groups"
];
}
set
{
ViewState[
"Groups"
] = value;
}
}
protected
void
Page_Load(
object
sender, EventArgs e)
{
RadGrid1.DataBound +=
new
EventHandler(RadGrid1_DataBound);
}
void
RadGrid1_DataBound(
object
sender, EventArgs e)
{
foreach
(GridGroupHeaderItem item
in
RadGrid1.MasterTableView.GetItems(GridItemType.GroupHeader))
{
if
(Groups.ContainsKey(item.DataCell.Text))
{
item.Expanded = (
bool
)Groups[item.DataCell.Text];
}
}
}
protected
void
RadGrid1_NeedDataSource(
object
source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
DataTable tbl =
new
DataTable();
DataColumn col =
new
DataColumn(
"ID"
);
col.DataType =
typeof
(
int
);
tbl.Columns.Add(col);
col =
new
DataColumn(
"Name"
);
col.DataType =
typeof
(
string
);
tbl.Columns.Add(col);
col =
new
DataColumn(
"Group"
);
col.DataType =
typeof
(
string
);
tbl.Columns.Add(col);
int
size = 15;
int
maxLen = size.ToString().Length;
for
(
int
i = 1; i <= size; i++)
{
tbl.Rows.Add(
new
object
[] { i,
"Name"
+ i.ToString(
"D"
+ maxLen),
"Group"
+ i % 5 });
}
RadGrid1.DataSource = tbl;
}
protected
void
RadGrid1_GroupsChanging(
object
source, GridGroupsChangingEventArgs e)
{
Groups.Clear();
foreach
(GridGroupHeaderItem item
in
RadGrid1.MasterTableView.GetItems(GridItemType.GroupHeader))
{
Groups[item.DataCell.Text] = item.Expanded;
}
}
protected
void
RadGrid1_ItemCommand(
object
source, GridCommandEventArgs e)
{
if
(e.CommandName == RadGrid.ExpandCollapseCommandName)
{
Groups[((GridGroupHeaderItem)e.Item).DataCell.Text] = !e.Item.Expanded;
}
}
Thanks,
Shinu.
0

Lasly
Top achievements
Rank 1
answered on 04 Oct 2012, 09:56 AM
Hi Shinu
Thanks for the reply.
It's work!
Thanks for the reply.
It's work!
But i need to used the radgrid in editmode=editForms, and if i use it in this mode it doesn't work.
0

Shinu
Top achievements
Rank 2
answered on 05 Oct 2012, 03:57 AM
Hi Lasly,
Please try setting the MasterTableView property GroupLoadMode to Client as shown below.
ASPX:
Thanks,
Shinu.
Please try setting the MasterTableView property GroupLoadMode to Client as shown below.
ASPX:
<
MasterTableView
GroupsDefaultExpanded
=
"false"
GroupLoadMode
=
"Client"
EditMode
=
"EditForms"
>
Thanks,
Shinu.
0

Lasly
Top achievements
Rank 1
answered on 08 Oct 2012, 10:56 AM
Thanks for the reply
The code doesn't work correctly. The property GroupLoadMode="Client" does not execute the event "GroupsChanging". Without the event, the group does not remain opened.
The code doesn't work correctly. The property GroupLoadMode="Client" does not execute the event "GroupsChanging". Without the event, the group does not remain opened.
0

Shinu
Top achievements
Rank 2
answered on 09 Oct 2012, 03:39 AM
Hi Lasly,
Unfortunately i couldn't replicate the issue. The GroupsChanging event is firing and the groups remains opened when edit button is clicked.
Thanks,
Shinu.
Unfortunately i couldn't replicate the issue. The GroupsChanging event is firing and the groups remains opened when edit button is clicked.
Thanks,
Shinu.
0

Lasly
Top achievements
Rank 1
answered on 09 Oct 2012, 08:00 AM
Hi
For more information, I attach an image with the current situation and another image with my expectations.
Thanks
0
Hi Lasly,
You could try to implement the approach provided in the following code-library:
http://www.telerik.com/community/code-library/aspnet-ajax/grid/persist-groups-expanded-state-on-rebind.aspx
I hope this will prove helpful.
Greetings,
Eyup
the Telerik team
You could try to implement the approach provided in the following code-library:
http://www.telerik.com/community/code-library/aspnet-ajax/grid/persist-groups-expanded-state-on-rebind.aspx
I hope this will prove helpful.
Greetings,
Eyup
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0

Lasly
Top achievements
Rank 1
answered on 11 Oct 2012, 01:16 PM
Thank you,
But the solution that you suggest me is the same that Shinu suggested me previously and it isn't the suitable one to solve the problem in my situation.
But the solution that you suggest me is the same that Shinu suggested me previously and it isn't the suitable one to solve the problem in my situation.
0
Hi Lasly,
If the suggested approach does not work as expected on your side, please open a support ticket and send us a sample runnable application demonstrating the problematic behavior. Or provide us the exact steps to reproduce the issue locally. Thus, we will be able to further analyze the issue and provide a proper solution.
Looking forward to your reply.
All the best,
Eyup
the Telerik team
If the suggested approach does not work as expected on your side, please open a support ticket and send us a sample runnable application demonstrating the problematic behavior. Or provide us the exact steps to reproduce the issue locally. Thus, we will be able to further analyze the issue and provide a proper solution.
Looking forward to your reply.
All the best,
Eyup
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0

Shinu
Top achievements
Rank 2
answered on 25 Oct 2012, 07:30 AM
Hi Lasly,
Please try the following code snippet when GroupsDefaultExpanded is set to false.
ASPX:
C#:
Thanks,
Shinu.
Please try the following code snippet when GroupsDefaultExpanded is set to false.
ASPX:
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
OnNeedDataSource
=
"RadGrid1_NeedDataSource"
AllowSorting
=
"true"
ShowGroupPanel
=
"True"
OnGroupsChanging
=
"RadGrid1_GroupsChanging"
OnItemCommand
=
"RadGrid1_ItemCommand"
AutoGenerateEditColumn
=
"true"
OnPreRender
=
"RadGrid1_PreRender"
>
<
ClientSettings
AllowDragToGroup
=
"True"
>
</
ClientSettings
>
<
MasterTableView
GroupsDefaultExpanded
=
"false"
GroupLoadMode
=
"Client"
EditMode
=
"EditForms"
>
<
GroupByExpressions
>
<
telerik:GridGroupByExpression
>
<
GroupByFields
>
<
telerik:GridGroupByField
FieldName
=
"Group"
/>
</
GroupByFields
>
<
SelectFields
>
<
telerik:GridGroupByField
FieldName
=
"Group"
/>
</
SelectFields
>
</
telerik:GridGroupByExpression
>
</
GroupByExpressions
>
</
MasterTableView
>
</
telerik:RadGrid
>
C#:
public
Hashtable Groups
{
get
{
if
(ViewState[
"Groups"
] ==
null
)
{
Hashtable res =
new
Hashtable();
ViewState[
"Groups"
] = res;
return
res;
}
return
(Hashtable)ViewState[
"Groups"
];
}
set
{
ViewState[
"Groups"
] = value;
}
}
protected
void
Page_Load(
object
sender, EventArgs e)
{
RadGrid1.DataBound +=
new
EventHandler(RadGrid1_DataBound);
}
void
RadGrid1_DataBound(
object
sender, EventArgs e)
{
foreach
(GridGroupHeaderItem item
in
RadGrid1.MasterTableView.GetItems(GridItemType.GroupHeader))
{
if
(Groups.ContainsKey(item.DataCell.Text))
{
item.Expanded = (
bool
)Groups[item.DataCell.Text];
}
}
}
protected
void
RadGrid1_NeedDataSource(
object
source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
DataTable tbl =
new
DataTable();
DataColumn col =
new
DataColumn(
"ID"
);
col.DataType =
typeof
(
int
);
tbl.Columns.Add(col);
col =
new
DataColumn(
"Name"
);
col.DataType =
typeof
(
string
);
tbl.Columns.Add(col);
col =
new
DataColumn(
"Group"
);
col.DataType =
typeof
(
string
);
tbl.Columns.Add(col);
int
size = 15;
int
maxLen = size.ToString().Length;
for
(
int
i = 1; i <= size; i++)
{
tbl.Rows.Add(
new
object
[] { i,
"Name"
+ i.ToString(
"D"
+ maxLen),
"Group"
+ i % 5 });
}
RadGrid1.DataSource = tbl;
}
protected
void
RadGrid1_GroupsChanging(
object
source, GridGroupsChangingEventArgs e)
{
Groups.Clear();
foreach
(GridGroupHeaderItem item
in
RadGrid1.MasterTableView.GetItems(GridItemType.GroupHeader))
{
Groups[item.DataCell.Text] = item.Expanded;
}
}
protected
void
RadGrid1_ItemCommand(
object
source, GridCommandEventArgs e)
{
if
(e.CommandName == RadGrid.ExpandCollapseCommandName)
{
Groups[((GridGroupHeaderItem)e.Item).DataCell.Text] = !e.Item.Expanded;
}
if
(e.CommandName == RadGrid.EditCommandName && RadGrid1.MasterTableView.GroupByExpressions.Count > 0)
group = e.Item.GroupIndex.Substring(0, e.Item.GroupIndex.LastIndexOf(
"_"
));
}
protected
void
Button1_Click(
object
sender, EventArgs e)
{
RadGrid1.Rebind();
}
string
group =
string
.Empty;
protected
void
RadGrid1_PreRender(
object
sender, EventArgs e)
{
if
(!
string
.IsNullOrEmpty(group))
{
GridItem[] items = RadGrid1.MasterTableView.GetItems(GridItemType.GroupHeader);
foreach
(GridGroupHeaderItem item
in
items)
if
(item.GroupIndex == group)
item.Expanded =
true
;
}
}
Thanks,
Shinu.
0

Lasly
Top achievements
Rank 1
answered on 02 Nov 2012, 04:12 PM
Thank you all, but I'm very sad .
I can not solve this problem.
(when press to save the changes, groups collapse. e.CommandName ="update" and e.Item.GroupIndex ="")
took me a long time to try to solve it.
( my personal tests. -with and without GroupsDefaultExpanded -
these posts:
http://www.telerik.com/community/forums/aspnet-ajax/grid/edit-won-t-show-when-using-groupsdefaultexpanded.aspx
http://www.telerik.com/community/forums/aspnet-ajax/grid/editor-won-t-open-when-groupsdefaultexpanded-is-false.aspx
http://www.telerik.com/community/forums/aspnet-ajax/grid/expanding-groups-propagates-to-detail-tables-with-grouploadmode- client.aspx
ecc
)
I would just work normally with a RadGrid grouped with item not expanded.
The problem is that using editform, filters, sorting etc etc groups collapse.
"This is the default behavior of the GroupsDefaultExpanded property when it's set to False" But how is that possible? it make no sense :-( :-(
since the proposed approach does not work as expected, I will open a support ticket.
thank you very much
I can not solve this problem.
(when press to save the changes, groups collapse. e.CommandName ="update" and e.Item.GroupIndex ="")
took me a long time to try to solve it.
( my personal tests. -with and without GroupsDefaultExpanded -
these posts:
http://www.telerik.com/community/forums/aspnet-ajax/grid/edit-won-t-show-when-using-groupsdefaultexpanded.aspx
http://www.telerik.com/community/forums/aspnet-ajax/grid/editor-won-t-open-when-groupsdefaultexpanded-is-false.aspx
http://www.telerik.com/community/forums/aspnet-ajax/grid/expanding-groups-propagates-to-detail-tables-with-grouploadmode- client.aspx
ecc
)
I would just work normally with a RadGrid grouped with item not expanded.
The problem is that using editform, filters, sorting etc etc groups collapse.
"This is the default behavior of the GroupsDefaultExpanded property when it's set to False" But how is that possible? it make no sense :-( :-(
since the proposed approach does not work as expected, I will open a support ticket.
thank you very much