Hi,
I have a nested (2-level) RadGrid sorted alphabetically by the name . After inserting a new record, I want to set the page index of the parent table to the newly created item without affecting the alphabetical sorting. I also want to automatically expand the new parent row to show its child table. Thanks.
I have a nested (2-level) RadGrid sorted alphabetically by the name . After inserting a new record, I want to set the page index of the parent table to the newly created item without affecting the alphabetical sorting. I also want to automatically expand the new parent row to show its child table. Thanks.
6 Answers, 1 is accepted
0
Hello Arnold Castro,
You can expand the currently inserted item in the ItemInserted event for RadGrid by setting to true its Expanded property. Also in this event you can set the PageIndex of the RadGrid to a precalculated value of the position of the newly inserted item.
Here is a code-sample illustrating this approach:
You can initially set a default sorting for the RadGrid. This way it will always be sorted as desired:
Hope this helps, feel free to contact us again if you have any further questions.
Kind regards,
Marin
the Telerik team
You can expand the currently inserted item in the ItemInserted event for RadGrid by setting to true its Expanded property. Also in this event you can set the PageIndex of the RadGrid to a precalculated value of the position of the newly inserted item.
Here is a code-sample illustrating this approach:
protected
void
RadGrid1_ItemInserted(
object
source, GridInsertedEventArgs e)
{
//expand the inserted item
e.Item.Expanded =
true
;
//get value of the column in the inserted item that we are sorting on
name = (e.Item[
"ProductName"
].Controls[0]
as
TextBox).Text;
//get the datasource for the grid and retrieve sorted records
DataView dataView = (DataView)SessionDataSource1.Select(DataSourceSelectArguments.Empty);
DataRow[] rows = dataView.Table.Select(
string
.Empty,
"ProductName ASC"
);
//find the inserted record and set the right page index for the grid.
for
(
int
i = 0; i < rows.Length; i++)
{
if
(rows[i].ItemArray[1].ToString()==name)
{
RadGrid1.CurrentPageIndex = i/(RadGrid1.PageSize-1);
}
}
}
You can initially set a default sorting for the RadGrid. This way it will always be sorted as desired:
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(!IsPostBack)
{
GridSortExpression sortExpr =
new
GridSortExpression();
sortExpr.FieldName =
"ProductName"
;
sortExpr.SortOrder = GridSortOrder.Ascending;
//Add sort expression, which will sort against first column
RadGrid1.MasterTableView.SortExpressions.AddSortExpression(sortExpr);
}
}
Hope this helps, feel free to contact us again if you have any further questions.
Kind regards,
Marin
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0

Web team
Top achievements
Rank 1
answered on 19 Nov 2010, 08:09 AM
Hi Marin,
I did try your solution but it seemed the ItemInserted event is not firing. I'm custom methods in inserting my new items. I read somewhere that ItemInserted only fires when using the default insert method of the Radgrid. Please advise an alternative solution.
Thanks.
I did try your solution but it seemed the ItemInserted event is not firing. I'm custom methods in inserting my new items. I read somewhere that ItemInserted only fires when using the default insert method of the Radgrid. Please advise an alternative solution.
Thanks.
0
Hello Arnold,
In any case you should have a reference to the newly inserted item or at least its value for the field that you are sorting on. The idea is as follows: to expand the item you need the item itself (ot its itemIndex in order to retrieve it from the collection), then you just set the Expanded property to true.
As for the setting of the correct page, you again need the value of the filed that you are sorting on, and the index of the newly inserted item in the items collection. In the previous code snippet I have obtained this through a itteration in all the sorted items in the datasource (you can of course apply a different aproach as far as it gets you the index of the item in the sorted collection).
As an alternative, you can try to move the code in the Page_PreRender event and execute it only after an item has been inserted. But have in mind that you will also need to rebind the grid for the changes to take effect.
Let me know how this works for you and if you need further assistance please open a formal support ticket and send as a code sample so that we can provide better support.
Sincerely yours,
Marin
the Telerik team
In any case you should have a reference to the newly inserted item or at least its value for the field that you are sorting on. The idea is as follows: to expand the item you need the item itself (ot its itemIndex in order to retrieve it from the collection), then you just set the Expanded property to true.
As for the setting of the correct page, you again need the value of the filed that you are sorting on, and the index of the newly inserted item in the items collection. In the previous code snippet I have obtained this through a itteration in all the sorted items in the datasource (you can of course apply a different aproach as far as it gets you the index of the item in the sorted collection).
As an alternative, you can try to move the code in the Page_PreRender event and execute it only after an item has been inserted. But have in mind that you will also need to rebind the grid for the changes to take effect.
Let me know how this works for you and if you need further assistance please open a formal support ticket and send as a code sample so that we can provide better support.
Sincerely yours,
Marin
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0

Web team
Top achievements
Rank 1
answered on 26 Nov 2010, 06:50 AM
I solved the problem. I created custom computation of page index in ItemDatabound event. Thanks
0

virtualcampus
Top achievements
Rank 1
answered on 24 Jan 2012, 08:14 AM
Hi
I am trying to achieve the same thing without luck. Could you post an example what you did to exapnd the child item after inserting the item.
Thanks
I am trying to achieve the same thing without luck. Could you post an example what you did to exapnd the child item after inserting the item.
Thanks
0

Raja M
Top achievements
Rank 1
answered on 29 Mar 2012, 09:51 AM
Hi,
I am also facing the same problem for expand the child item after inserting the parent.
I just tried..
But it doesn't work.
Any solution...?.
Regards,
Raja M
I am also facing the same problem for expand the child item after inserting the parent.
I just tried..
e.item.Expanded=
true
;
But it doesn't work.
Any solution...?.
Regards,
Raja M