This is a migrated thread and some comments may be shown as answers.

Hierarchical Grid - Edit Selected option

2 Answers 74 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rajiv
Top achievements
Rank 1
Rajiv asked on 15 Oct 2008, 04:08 PM
Hello,
        This is my second post with regards to the issue that I am facing with Hierarchical Grid. Sorry for reposting it, but I thought it would be better to explain my problem again with the sample code.

I have a hierarchical RadGrid, where both the parent and the child table records can be updated. The issue is with the "Edit Selected" button of the child table. When the user clicks on any page other than page 1 of the child table and then selects any item(s) for edit using "Edit Selected Items" command button, the records that are shown in edit mode are from page no. 1 and not the actual one that were selected. At the same time the individual "Edit" button for each record on the child control work fine. So I am not very sure why "Edit Selected" option is not working.

To demostrate my problem I have created a simple sample page and I am attaching the code for the same (This page doesn’t have the code to actually the update the records as I was just testing the “Edit Selected” option).

 

<form id="form1" runat="server">

 

 

<asp:ScriptManager ID="ScriptManager1" runat="server" />

 

 

<telerik:RadAjaxManager runat="server" ID="RadAjaxManager1">

 

 

<AjaxSettings>

 

 

<telerik:AjaxSetting AjaxControlID="RadGrid1">

 

 

<UpdatedControls>

 

 

<telerik:AjaxUpdatedControl ControlID="RadGrid1" />

 

 

</UpdatedControls>

 

 

</telerik:AjaxSetting>

 

 

</AjaxSettings>

 

 

</telerik:RadAjaxManager>

 

 

<div>

 

 

<telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource1" GridLines="None"

 

 

AutoGenerateEditColumn="true" AllowMultiRowEdit="true" AllowMultiRowSelection="true"

 

 

PagerStyle-Mode="NextPrevAndNumeric">

 

 

<MasterTableView AutoGenerateColumns="True" DataSourceID="SqlDataSource1" DataKeyNames="CategoryID"

 

 

Name="MasterTableView" CommandItemDisplay="Top" PageSize="3" AllowPaging="true">

 

 

<CommandItemTemplate>

 

 

<asp:LinkButton Style="vertical-align: bottom" ID="btnEditSelected1" runat="server"

 

 

CommandName="EditSelected" CausesValidation="false" Visible='<%# RadGrid1.EditIndexes.Count == 0 %>'><img style="border:0px;vertical-align:middle;" alt="" src="../Include/Images/Edit.gif" /> Edit Selected Records</asp:LinkButton>

 

 

<asp:LinkButton ID="btnCancel1" runat="server" CommandName="CancelAll" CausesValidation="false"

 

 

Visible='<%# (RadGrid1.EditIndexes.Count > 0 || RadGrid1.MasterTableView.IsItemInserted) %>'><img style="border:0px;vertical-align:middle;" alt="" src="../Include/Images/Cancel.gif" /> Cancel editing</asp:LinkButton>

 

 

</CommandItemTemplate>

 

 

<DetailTables>

 

 

<telerik:GridTableView DataKeyNames="CategoryID" AutoGenerateColumns="true" DataSourceID="SqlDataSource2"

 

 

CommandItemDisplay="Top" AllowPaging="true" PageSize="3">

 

 

<CommandItemTemplate>

 

 

<asp:LinkButton Style="vertical-align: bottom" ID="btnEditSelected" runat="server"

 

 

CommandName="EditSelected" CausesValidation="false" Visible='<%# RadGrid1.EditIndexes.Count == 0 %>'><img style="border:0px;vertical-align:middle;" alt="" src="../Include/Images/Edit.gif" /> Edit Selected Records</asp:LinkButton>

 

 

<asp:LinkButton ID="btnCancel" runat="server" CommandName="CancelAll" CausesValidation="false"

 

 

Visible='<%# (RadGrid1.EditIndexes.Count > 0 || RadGrid1.MasterTableView.IsItemInserted) %>'><img style="border:0px;vertical-align:middle;" alt="" src="../Include/Images/Cancel.gif" /> Cancel editing</asp:LinkButton>

 

 

</CommandItemTemplate>

 

 

<ParentTableRelation>

 

 

<telerik:GridRelationFields DetailKeyField="CategoryID" MasterKeyField="CategoryID" />

 

 

</ParentTableRelation>

 

 

</telerik:GridTableView>

 

 

</DetailTables>

 

 

</MasterTableView>

 

 

<ClientSettings>

 

 

<Selecting AllowRowSelect="true" />

 

 

</ClientSettings>

 

 

</telerik:RadGrid>

 

 

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"

 

 

SelectCommand="SELECT * FROM [Categories]"></asp:SqlDataSource>

 

 

<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"

 

 

SelectCommand="SELECT * FROM [Products] WHERE ([CategoryID] = @CategoryID)">

 

 

<SelectParameters>

 

 

<asp:Parameter Name="CategoryID" Type="Int32" />

 

 

</SelectParameters>

 

 

</asp:SqlDataSource>

 

 

</div>

 

 

</form>

 

Thank you for your time.

Best Regards,
Rajiv



2 Answers, 1 is accepted

Sort by
0
Accepted
Iana Tsolova
Telerik team
answered on 20 Oct 2008, 09:07 AM
Hi Rajiv,

I tested your sample and observed the described behavior. However to make the EditedSelected command work as desired in hierarchical grid, you need to perform custom handling of it. You can try the following code in the grid ItemCommand event handler:

protected void RadGrid1_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)  
{  
    if (e.CommandName == RadGrid.EditSelectedCommandName && e.Item.OwnerTableView.Name == "Products")  //where "Products" is the name of the detail table  
    {  
        foreach (GridDataItem dataItem in RadGrid1.SelectedItems)  
        {  
            dataItem.Edit = true;  
        }  
        RadGrid1.SelectedItems[0].OwnerTableView.Rebind();              
        e.Canceled = true;  
    }  
}     

Give it a try and let me know if this works for you.

Kind regards,
Iana
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Rajiv
Top achievements
Rank 1
answered on 21 Oct 2008, 08:42 AM
Hi Iana,

 Thank you for your reply. The given work around is working fine.

Best Regards,
Rajiv
Tags
Grid
Asked by
Rajiv
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Rajiv
Top achievements
Rank 1
Share this question
or