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

RadGrid OnItemCommand in Hierarchical grid

6 Answers 367 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Daniel asked on 08 Apr 2011, 03:52 PM
I have a radgrid with a MatersTableView housing 2 GridTableViews (not nested).

I have 2 issues I am trying to understand
  1. When I click on the "expand", the grid expands properly and the GridTableViews populate properly.  However, when I click on "Collapse" subsequently, the row does not collapse.
  2. Each GridTable has image buttons in them.  When clicked, the OnItemCommand is not fired, and the Grid collapses.  I do not that when I click "Expand" the OnItemCommand is fired with "ExpandCollapse" as the e.CommandName, and e.CommandArgument as String.Empty.

NOTE: all ItemCommands work when in non hierarchical grids.

  • How do I collapse and expanded row?
  • How do I capture a ItemCommand in the MasterTableView and GridTableViews? 

Below is my code

Thanks in advance

<telerik:RadAjaxManagerProxy ID="RadAM_CasePaymentSubmissions" runat="server">
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="RadAM_CasePaymentSubmissions">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="paymentSubmissionGrid" />
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManagerProxy>
<telerik:RadGrid ID="paymentSubmissionGrid" OnPreRender="paymentSubmissionGrid_PreRender"
    EnableViewState="true" ShowStatusBar="true" Skin="Office2007" OnDetailTableDataBind="paymentSubmissionGrid_DetailTableDataBind"
    OnNeedDataSource="paymentSubmissionGrid_NeedDataSource" OnItemDataBound="paymentSubmissionGrid_OnItemDatabound"
    OnItemCommand="paymentSubmissionGrid_OnItemCommand"
    runat="server" AutoGenerateColumns="False" PageSize="7" AllowSorting="True" 
    AllowPaging="True" GridLines="None">
  
    <PagerStyle Mode="NumericPages"></PagerStyle>
    <MasterTableView Name="HcfaSubmissions" DataKeyNames="PaymentSubmissionId">
        <DetailTables>
            <telerik:GridTableView DataKeyNames="PaymentSubmissionId" Name="Resubmit" Width="100%"
                runat="server" ItemStyle-BackColor="Ivory" AlternatingItemStyle-BackColor="Ivory">                
                <Columns>
                    <telerik:GridTemplateColumn AllowFiltering="false" DataType="System.String" SortExpression="PaymentSubmissionId"
                        HeaderText="Submission Id" HeaderButtonType="TextButton" DataField="PaymentSubmissionId"
                        UniqueName="RePaymentSubmissionId">
                        <HeaderStyle HorizontalAlign="Left" Wrap="False" Width="50px" />
                        <ItemStyle Width="50px" Wrap="false" />
                        <ItemTemplate>
                            <asp:Literal ID="ReSubmissionIdLiteral" runat="server"></asp:Literal>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridBoundColumn SortExpression="SubmissionDate" HeaderText="Date Resubmitted"
                        ItemStyle-Width="100px" DataType="System.DateTime" HeaderButtonType="TextButton"
                        DataField="SubmissionDate" UniqueName="ReSubmissionDate" DataFormatString="{0:MM/dd/yyyy}">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn SortExpression="Status" HeaderText="Status" HeaderButtonType="TextButton" ItemStyle-Width="500px"
                        DataField="Status" UniqueName="ReStatus">
                    </telerik:GridBoundColumn>
                    <telerik:GridTemplateColumn>
                        <HeaderStyle HorizontalAlign="Left" Wrap="False" />
                        <ItemStyle Width="40px" Wrap="false" HorizontalAlign="Center" />
                        <ItemTemplate>
                            <div style="floatleft;">
                                <asp:ImageButton ID="viewResubmitHCFA" AlternateText="View" runat="server" CommandArgument='<%#DataBinder.Eval(Container.DataItem,"PaymentSubmissionId") %>'
                                    ImageAlign="Middle" ImageUrl="~/images/pdf.jpg" ToolTip="View resubmission" />
                            </div>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                </Columns>
            </telerik:GridTableView>
            <telerik:GridTableView DataKeyNames="BillSubmissionId" Name="Procedures" Width="100%"
                runat="server" ItemStyle-BackColor="AntiqueWhite" AlternatingItemStyle-BackColor="AntiqueWhite">
                <Columns>
                    <telerik:GridBoundColumn UniqueName="CaseProviderDetailId" DataField="CaseProviderDetails.CaseProviderDetailId"
                        HeaderText="Bill ID" ItemStyle-Width="40px" ItemStyle-HorizontalAlign="Left"
                        DataType="System.Int32" />
                    <telerik:GridTemplateColumn AllowFiltering="false" UniqueName="CaseProviderDetails.CPTCode.Code"
                        DataField="CaseProviderDetails.CPTCode.Code" DataType="System.String" HeaderText="CPT Code">
                        <HeaderStyle HorizontalAlign="Left" Wrap="False" Width="500px" />
                        <ItemStyle Width="500px" Wrap="false" />
                        <ItemTemplate>
                            <asp:Literal ID="cptLiteral" runat="server"></asp:Literal>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridBoundColumn UniqueName="CaseProviderDetailsDOS" DataField="CaseProviderDetails.DOS"
                        HeaderText="DOS" ItemStyle-Width="75px" ItemStyle-HorizontalAlign="Left" DataType="System.DateTime"
                        DataFormatString="{0:MM/dd/yyyy}" />
                    <telerik:GridTemplateColumn AllowFiltering="false" UniqueName="CaseProviderDetailsReceivable"
                        DataField="CaseProviderDetails.Receivable" DataType="System.Decimal" HeaderText="Bill Amount">
                        <HeaderStyle HorizontalAlign="Left" Wrap="False" Width="75px" />
                        <ItemStyle Width="75px" Wrap="false" />
                        <ItemTemplate>
                            <asp:Literal ID="ReceivableLiteral" runat="server"></asp:Literal>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridTemplateColumn AllowFiltering="false" UniqueName="StatusName" DataType="System.String"
                        HeaderText="Status">
                        <HeaderStyle HorizontalAlign="Left" Wrap="False" Width="110px" />
                        <ItemStyle Width="75px" Wrap="false" />
                        <ItemTemplate>
                            <asp:Literal ID="StatusLiteral" runat="server"></asp:Literal>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridTemplateColumn>
                        <HeaderStyle HorizontalAlign="Left" Wrap="False" />
                        <ItemStyle Width="40px" Wrap="false" HorizontalAlign="Center" />
                        <ItemTemplate>
                            <div style="floatleft;">
                                <asp:ImageButton ID="editDetails" AlternateText="Edit" runat="server" ImageAlign="Middle"
                                    ImageUrl="~/images/EditInformationHS.png" ToolTip="Edit Bill" />
                            </div>
                            <div style="floatright;">
                                <asp:ImageButton ID="viewDetails" AlternateText="View" runat="server" CommandArgument='<%#DataBinder.Eval(Container.DataItem,"CaseProviderDetails.CaseProviderDetailId") %>'
                                    CommandName="viewDetails" ImageAlign="Middle" ImageUrl="~/images/Search.gif"
                                    ToolTip="View Details" />
                            </div>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                </Columns>
            </telerik:GridTableView>
        </DetailTables>
        <Columns>
            <telerik:GridTemplateColumn AllowFiltering="false" DataType="System.String" SortExpression="PaymentSubmissionId"
                HeaderText="Submission Id" HeaderButtonType="TextButton" DataField="PaymentSubmissionId"
                UniqueName="PaymentSubmissionId">
                <HeaderStyle HorizontalAlign="Left" Wrap="False" Width="110px" />
                <ItemStyle Width="50px" Wrap="false" />
                <ItemTemplate>
                    <asp:Literal ID="SubmissionIdLiteral" runat="server"></asp:Literal>
                </ItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridBoundColumn SortExpression="SubmissionDate" HeaderText="Submission Date"
                ItemStyle-Width="100px" DataType="System.DateTime" HeaderButtonType="TextButton"
                DataField="SubmissionDate" UniqueName="SubmissionDate" DataFormatString="{0:MM/dd/yyyy}">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn SortExpression="Status" HeaderText="Status" HeaderButtonType="TextButton" ItemStyle-Width="500px"
                DataField="Status" UniqueName="Status">
            </telerik:GridBoundColumn>
            <telerik:GridTemplateColumn>
                <HeaderStyle HorizontalAlign="Left" Wrap="False" />
                <ItemStyle Width="40px" Wrap="false" HorizontalAlign="Center" />
                <ItemTemplate>
                    <div style="floatleft;">
                        <asp:ImageButton ID="viewHCFA" AlternateText="View" runat="server" ImageAlign="Middle"
                            ImageUrl="~/images/pdf.jpg" ToolTip="View HCFA" />
                    </div>
                    <div style="floatright;">
                        <asp:ImageButton ID="resubmit" AlternateText="Resubmit" runat="server" CommandArgument='<%#DataBinder.Eval(Container.DataItem,"PaymentSubmissionId") %>'
                            CommandName="resubmit" ImageAlign="Middle" ImageUrl="~/images/resubmit.png" ToolTip="Resubmit" />
                    </div>
                </ItemTemplate>
            </telerik:GridTemplateColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>




private void GetPaymentSubmission(Int32 caseId, Boolean bind)
        {            
            List<PaymentSubmission> paymentSubmissions = new List<PaymentSubmission>();
            paymentSubmissions = PaymentSubmission.GetByCaseId(caseId);
 
            paymentSubmissionGrid.DataSource = paymentSubmissions;
 
            if (bind)
                paymentSubmissionGrid.DataBind();
 
        }
 
        protected void paymentSubmissionGrid_DetailTableDataBind(object source, GridDetailTableDataBindEventArgs e)
        {
            List<PaymentSubmission> paymentSubmissions;
            Int32 paymentSubmissionId;
            GridDataItem dataItem;
            
            switch (e.DetailTableView.Name)
            {
                case "Procedures":
 
                    dataItem = (GridDataItem)e.DetailTableView.ParentItem;
                    paymentSubmissionId = Int32.Parse(dataItem.GetDataKeyValue("PaymentSubmissionId").ToString());
 
                    paymentSubmissions = new List<PaymentSubmission>();
                    paymentSubmissions = PaymentSubmission.GetByCaseId(3635);
                    
                    List<BillSubmission> billsDetails = (paymentSubmissions.Where(p => p.PaymentSubmissionId == paymentSubmissionId).FirstOrDefault())
                                                                .BillSubmission.ToList();
 
                    e.DetailTableView.DataSource = billsDetails;
 
                    break;
 
                case "Resubmit":
 
                    dataItem = (GridDataItem)e.DetailTableView.ParentItem;
                    paymentSubmissionId = Int32.Parse(dataItem.GetDataKeyValue("PaymentSubmissionId").ToString());
 
                    paymentSubmissions = new List<PaymentSubmission>();
                    paymentSubmissions = PaymentSubmission.GetByCaseId(3635);
 
                    List<PaymentSubmission> resubmitSubmissions = (paymentSubmissions
								.Where(p => p.PaymentSubmissionId == paymentSubmissionId)
								.FirstOrDefault()).Children.ToList();
 
                     e.DetailTableView.DataSource = resubmitSubmissions;
                    
                    break;
            }
            
        }
 
        protected void paymentSubmissionGrid_OnItemDatabound(object sender, GridItemEventArgs e)
        {
            if ((e.Item is GridDataItem) && (e.Item.OwnerTableView.Name == "Procedures"))
            {
                
                BillSubmission lineItem = e.Item.DataItem as BillSubmission;
 
                if (!(e.Item.FindControl("ReceivableLiteral") == null))
                {
                    Literal ReceivableLiteral = e.Item.FindControl("ReceivableLiteral"as Literal;
                    ReceivableLiteral.Text = String.Format("{0:c}", lineItem.CaseProviderDetails.Receivable);
                }
 
                if (!(e.Item.FindControl("StatusLiteral") == null))
                {
                    Literal StatusLiteral = e.Item.FindControl("StatusLiteral"as Literal;
                    StatusLiteral.Text = lineItem.BillSubmissionResponse.Name;                    
                }
 
                if (lineItem.CaseProviderDetails.CPTCode != null)
                {
                    if (!(e.Item.FindControl("cptLiteral") == null))
                    {
                        Literal cptLiteral = e.Item.FindControl("cptLiteral"as Literal;
                        cptLiteral.Text = String.Format("{0}-{1}"						lineItem.CaseProviderDetails.CPTCode.Code, 
						lineItem.CaseProviderDetails.CPTCode.Description);
                    }
                }
 
                if (!(e.Item.FindControl("editDetails") == null))
                {
                    ImageButton editDetails = e.Item.FindControl("editDetails"as ImageButton;
                    editDetails.Attributes.Add("onclick"String.Format("EditBill('{0}','{1}','{2}'); return false;"						lineItem.CaseProviderDetails.CaseProviderDetailId.ToString(), 
						lineItem.CaseProviderDetails.Case.CaseId.ToString(), "Edit Bill"));
                }
        
            }
 
            if ((e.Item is GridDataItem) && ( e.Item.OwnerTableView.Name == "Resubmit"))
            {
                PaymentSubmission submission = e.Item.DataItem as PaymentSubmission;
 
                if (!(e.Item.FindControl("reSubmissionIdLiteral") == null))
                {
                    Literal SubmissionIdLiteral = e.Item.FindControl("reSubmissionIdLiteral"as Literal;
                    if(submission.Parent != null)
                        SubmissionIdLiteral.Text = String.Format("HCFA-{0}:{1}", submission.Parent.PaymentSubmissionId, 1);
                }
 
            }
 
            if ((e.Item is GridDataItem) && (e.Item.OwnerTableView.Name == "HcfaSubmissions"))
            {
                PaymentSubmission submission = e.Item.DataItem as PaymentSubmission;
 
                if (!(e.Item.FindControl("SubmissionIdLiteral") == null))
                {
                    Literal SubmissionIdLiteral = e.Item.FindControl("SubmissionIdLiteral"as Literal;
                    SubmissionIdLiteral.Text = String.Format("HCFA-{0}", submission.PaymentSubmissionId);                    
                }
 
                if (submission.Status == "Closed")
                {
                    if (!(e.Item.FindControl("resubmit") == null))
                    {
                        ImageButton resubmit = e.Item.FindControl("resubmit"as ImageButton;
                        resubmit.Visible = false;
                    }
                }     
            }
 
            
        }
 
        protected void paymentSubmissionGrid_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
        {
            if (!e.IsFromDetailTable)
            {
                GetPaymentSubmission(3635, false);
            }
        }
 
        protected void paymentSubmissionGrid_OnItemCommand(object sender, GridCommandEventArgs e)
        {
            switch ((e.Item).OwnerTableView.Name)
            {
                case "Procedures":
 
                    break;
 
                case "Resubmit":
 
                    break;
 
                case "HcfaSubmissions":
 
                    switch (e.CommandName)
                    {                       
                        case "viewDetails":
                            
                            break;
                    }
                    break;
            }
        }    
    }
}

6 Answers, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 14 Apr 2011, 08:27 AM
Hi Daniel,

It is not a supported scenario to mix simple with advanced data binding. Please, take a look at the following demo to see how a hierarchical grid should be bound programmatically:

Programmatic Binding (you should never call DataBind() in NeedDataSource and DetailTableDataBind)

Additionally, when ajaxifying the grid, it is good to have a setting where the control updates itself.

Best wishes,
Tsvetina
the Telerik team

Browse the vast support resources we have to jump start 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
Daniel
Top achievements
Rank 1
answered on 14 Apr 2011, 08:40 AM
Thanks for you reply Tsvetina 

I am not calling Databind() in the NeedDataSource or DetailTableDataBind.  Both these would throw errors and not bing the grid at all.

If you look at the NeedDatasource, it is passing a boolean of false, and thus bypassing the databind() in the GetPaymentSubmission.  Nowhere do I call DataBind in the DetailTableDataBind.

As far as the article, yes, it is the one that I based my code on.

To be clear, the grid binds, the data is present, the expand works, it is a matter of the OnItemCommand not firing when a button is clicked other than the collapse, and the collapse not collapsing the row.  I suspect they are related, and am sure it is something in my implementation, but I do not believe it is the fact that I am calling a Databind() as you suggest

Please have another look, this remains a problem for me and is one of the primary reasons for evaluating your product

Thanks again in advance
0
Tsvetina
Telerik team
answered on 18 Apr 2011, 12:51 PM
Hello Daniel,

By default, if no errors are present and the HierarchyLoadMode of the GridTableView is different from "Client" an ItemCommand event will always be fired on each Expand/Collapse. Just in case you can also check how the grid behaves if there is no AJAX on the page (set EnableAJAX="false" in the main RadAjaxManager control). Other than this, I cannot notice an obvious problem in your code.

If you cannot notice any javascript or other errors, and the debugger on ItemCommand continues to not be hit when expanding, the best option would be to submit a formal support ticket and attach to it a runnable project replicating the issue. This way we will be able to help you out faster and with a more straight-to-the-point answer.

All the best,
Tsvetina
the Telerik team

Browse the vast support resources we have to jump start 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
Artem
Top achievements
Rank 1
answered on 07 Aug 2012, 01:38 AM
Has this issue gotten any conclusion? Did it result in a support ticket? I have a similar issue, where upon adding an item in pop-up mode, nested group expanding / collapsing breaks.
After the item has been added, I can expand/ collapse any group header item once (!) without an issue. Any subsequent expand/collapse causes the grid to post back, but the ItemCommand is not fired. Furthermore, the grid becomes corrupted with data missing in some rows or group headers containing some of the data instead of headers.
If at this point any other command is invoked, besides expand/collapse, the grid rebinds properly and the issue goes away until another insert.
There's only the MasterTableView with a declarative data source, but it has two-level grouping. Without digging further this feels like a bug with the RadGrid control. So, before I send you heaps of code, if you have any knowledge of bugs related to this, please let us know.

Thanks,
-art
0
ross
Top achievements
Rank 1
answered on 08 Aug 2012, 04:38 PM
Im having this problem too, an update would be appreciated.
0
Tsvetina
Telerik team
answered on 09 Aug 2012, 12:17 PM
Hello Art,

A formal support ticket has not been opened for this case. Furthermore, it is in a hierarchical grid context, while your grid only has grouping, if I correctly understand. So, most probably the cause of the issue on your side is different and we have not received reports of such common issue with the control.
I would advise you to open a ticket and send us a runnable page to debug and see if there is a bug in the control or a problem with the implementation.

All the best,
Tsvetina
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.
Tags
Grid
Asked by
Daniel
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
Daniel
Top achievements
Rank 1
Artem
Top achievements
Rank 1
ross
Top achievements
Rank 1
Share this question
or