NestedViewTemplate ItemCommand Bug

2 posts, 0 answers
  1. Christian
    Christian avatar
    64 posts
    Member since:
    Apr 2008

    Posted 20 Apr 2015 Link to this post

     

    When we upgraded to 2015 Q1 release our itemCommand for a linkbutton inside a NesterViewTemplate stopped working. after reading the latest release notes it stated something which we thought would fix this but it did not, the note said,

    The ItemCommand event is not fired when row was clicked and the grid is placed in NestedViewTemplate of another RadGrid.

    But we don't have a grid relation between separate grids, or row click, but our issue is the ItemCommand event inside the first grid is not fired. our linkbutton (ID "lbDeletePart" below) should fire but does not..

    <telerik:RadGrid ID="grArtList" runat="server" AllowSorting="true" onneeddatasource="grArtList_NeedDataSource" AutoGenerateColumns="False" CellSpacing="0" GridLines="None"
            BorderStyle="None" Width="100%" AllowPaging="True" PageSize="20" onitemdatabound="grArtList_ItemDataBound" onitemcreated="grArtList_ItemCreated" EnableLinqExpressions="false"
            onitemcommand="grArtList_ItemCommand" onprerender="grArtList_PreRender" EnableEmbeddedSkins="false" Skin="SLP" RegisterWithScriptManager="true"
            AllowMultiRowSelection="true" OnColumnCreated="grArtList_ColumnCreated">
            <ClientSettings DataBinding-ShowEmptyRowsOnLoad="false">
                <ClientEvents OnRowMouseOver="rowExpand" OnRowSelected="rowExpand" OnRowCreated="checkBlocked" />
                <Selecting AllowRowSelect="true" />
            </ClientSettings>
        <MasterTableView ShowHeadersWhenNoRecords="true" ShowGroupFooter="true" DataKeyNames="art_artnr, art_id, koppl_id, CartQuantity" ClientDataKeyNames="art_artnr, art_id, koppl_id, CartQuantity" HierarchyLoadMode="Client" CommandItemDisplay="Top">
            <ExpandCollapseColumn Visible="false"></ExpandCollapseColumn>
            <CommandItemTemplate>
                <div style="padding: 5px 5px;">
                      
                    <asp:LinkButton ID="lbAddPart" runat="server"><img src="Images/icons/24x24/Add.png" title="Add Part to Vehicle"/></asp:LinkButton>  
                    <asp:LinkButton ID="lbCopyParts" runat="server" CommandName="CopySelected" Visible="True"><img src="Images/icons/24x24/copy.png" title="Copy selected parts to another Vehicle" /></asp:LinkButton>  
                </div>
            </CommandItemTemplate>
     
            <GroupByExpressions>
              <telerik:GridGroupByExpression>
                <SelectFields>
                  <telerik:GridGroupByField FieldName="category" HeaderText="category" />
                </SelectFields>
                <GroupByFields>
                  <telerik:GridGroupByField FieldName="category" SortOrder="Descending" />
                </GroupByFields>
              </telerik:GridGroupByExpression>
            </GroupByExpressions>
     
            <GroupHeaderTemplate>
                <table style="border:none;">
                    <tr>
                        <td>
                            <asp:Label runat="server" ID="Label1" CssClass="txtGridGroupHeader" Text='<%# Eval("category") %>'>
                            </asp:Label>
                        </td>
                        <td>
                            <asp:Label runat="server" ID="labGroupCatCode" Visible="false" Text='<%# Eval("artkod") %>'></asp:Label>
                            <asp:LinkButton ID="lbAddPartByKat" runat="server" Visible="false"><img style="border:0; vertical-align:middle;" alt="" src="Images/icons/16x16/Add.png"/>Add new part to category</asp:LinkButton>
                            <asp:LinkButton ID="lbAddDrawing" runat="server" Visible="false"><img style="border:0; vertical-align:middle;" alt="" src="Images/icons/16x16/Add.png"/>Add new drawing to category</asp:LinkButton>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2">
                            <telerik:RadListView runat="server" ID="liDrawingMiniatures" ItemPlaceholderID="miniaturesContainer">
                                <LayoutTemplate>
                                    <div style="width:100%;" id="list">
                                        <asp:Panel ID="miniaturesContainer" runat="server">
     
                                        </asp:Panel>
                                    </div>
                                </LayoutTemplate>
     
                                <ItemTemplate>
                                    <div id="miniatureItem" class="drawingMiniatureContainer" style="float:left; text-align:center;">
                                        <a href='<%# "drawing.aspx?drawingID=" + Eval("abd_id") %>'><img id="imgMiniature" src='<%# Eval("abd_path")%>' height="125" alt="" /><br />
                                        <asp:Label runat="server" ID="labDrawingName" Text='<%# Eval("Name")%>'></asp:Label></a><br /><br />
                                    </div>
                                </ItemTemplate>
                            </telerik:RadListView>
                        </td>
                    </tr>
                </table>
            </GroupHeaderTemplate>
     
            <Columns>
                <telerik:GridBoundColumn DataField="art_artnr" UniqueName="art_artnr" Display="false" HeaderText="art_artnr" CurrentFilterFunction="NoFilter" FilterListOptions="VaryByDataType" ForceExtractValue="None" ReadOnly="true">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="art_id" FilterControlAltText="Filter art_id column" UniqueName="art_id" HeaderText="art_id">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="blocked" UniqueName="blocked" HeaderText="" HeaderStyle-Width="2px" ItemStyle-Width="2px" CurrentFilterFunction="NoFilter" FilterListOptions="VaryByDataType" ForceExtractValue="None" ReadOnly="true">
                </telerik:GridBoundColumn>
                <telerik:GridTemplateColumn UniqueName="chkOrdersvar" ItemStyle-Width="8px" HeaderStyle-Width="8px">
                <ItemTemplate>
                    <asp:CheckBox id="chkCopy" runat="server" Text=" "></asp:CheckBox>
                </ItemTemplate>
                <HeaderTemplate>
                    <input id="chkCheckAll" onchange="for (var i = 0; i < document.all.length; i++){ if (document.all(i).id.indexOf('chkCopy') > 0) { document.all(i).checked = chkCheckAll.checked; }}" type="checkbox" value="ChangeMe" />
                </HeaderTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridTemplateColumn HeaderText="Art No." SortExpression="art_artnr" DataField="art_artnr" UniqueName="art" ItemStyle-Width="115px" >
                    <ItemTemplate>
                        <asp:HyperLink ID="hlArtnr" runat="server" NavigateUrl="#" Text='<%# Eval("art_artnr") %>'></asp:HyperLink>
                        <div id="container">
                           <div id="box"> </div>
                        </div>
                    </ItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridTemplateColumn HeaderText="Name" SortExpression="ben" DataField="ben" >
                    <ItemTemplate>
                        <asp:HyperLink ID="hlArtben" runat="server" NavigateUrl="#" Text='<%# Eval("ben") %>'></asp:HyperLink>
                        <asp:Label ID="labNews" CssClass="labNews" runat="server" Visible="false"> (New)</asp:Label>
                    </ItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridBoundColumn DataField="refnr" FilterControlAltText="Filter ritning column" UniqueName="ritning" HeaderText="Volvo ref.">
                </telerik:GridBoundColumn>
                <telerik:GridNumericColumn DataField="display_price" DecimalDigits="2" FilterControlAltText="Filter Price column" UniqueName="price" HeaderText="Price" DataFormatString="{0:N}" DataType="System.Decimal">
                    <HeaderStyle HorizontalAlign="Right" />
                    <ItemStyle HorizontalAlign="Right" />
                </telerik:GridNumericColumn>
                 <telerik:GridBoundColumn DataField="test" FilterControlAltText="Filter InStock column" UniqueName="test" HeaderText="test">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="category" FilterControlAltText="Filter category column" UniqueName="category" HeaderText="category">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="koppl_id" UniqueName="koppl_id" HeaderText="koppl_id">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="nyhet" UniqueName="nyhet" HeaderText="News">
                </telerik:GridBoundColumn>
            </Columns>
     
            <NestedViewSettings>
              <ParentTableRelation>
                <telerik:GridRelationFields DetailKeyField="art_id" MasterKeyField="art_id" />
              </ParentTableRelation>
            </NestedViewSettings>
            <NestedViewTemplate>
              <asp:Panel ID="NestedViewPanel" runat="server" CssClass="divArtDetailsView">
                <div class="contactWrap">
                    <table width="100%" cellpadding="0" cellspacing="0">
                        <tr>
                            <td width="130px">
                                <asp:image runat="server" ID="imgArt" src="" />
                            </td>
                            <td style="vertical-align:top;">
                                <asp:LinkButton ID="lbEditPart" runat="server" style="display:none;"><img style="border:0px;vertical-align:middle;" alt="" src="Images/icons/16x16/edit.png"/>Edit attributes</asp:LinkButton>
                                <asp:LinkButton ID="lbDeletePart" runat="server" style="display:none;" CommandName="deletePart"><img style="border:0px;vertical-align:middle;" alt="" src="Images/icons/16x16/delete.png"/>Delete part</asp:LinkButton>
                                <asp:Label runat="server" ID="labAttribut" Text=""></asp:Label>
                            </td>
                            <td style="vertical-align:top; text-align:right; padding-right:5px;">
                                <telerik:RadButton runat="server" ID="btnPinRow" AutoPostBack="false" ButtonType="ToggleButton" ToggleType="CheckBox" Checked="false" OnClientCheckedChanged="pinChanged">
                                    <ToggleStates>
                                        <telerik:RadButtonToggleState Width="16px" IsBackgroundImage="true" ImageUrl="images/pinned.png" />
                                        <telerik:RadButtonToggleState Width="16px" IsBackgroundImage="true" ImageUrl="images/unpinned.png" HoveredImageUrl="images/pinned.png" Selected="false" />
                                    </ToggleStates>
                                </telerik:RadButton>
                                <br /><br />
                                <telerik:RadNumericTextBox runat="server" ID="txtAnt" Width="45px" NumberFormat-DecimalDigits="0" Value="1" MinValue="0"></telerik:RadNumericTextBox>
                                <telerik:RadButton runat="server" ID="btnAddToCart" Text="Add" Skin="Telerik" AutoPostBack="False" OnClientClicked="btnAddToCart_clicked"></telerik:RadButton>
                                <br />
                                <asp:Label runat="server" ID="labAvailability" Text="Availability:"></asp:Label>
                                <asp:Label runat="server" ID="labStock" Text=""></asp:Label>
                            </td>
                        </tr>
                    </table>
                </div>
              </asp:Panel>
            </NestedViewTemplate>
        </MasterTableView>
     
        <FilterMenu EnableImageSprites="False"></FilterMenu>
     

     

        </telerik:RadGrid

     

     

    protected void grArtList_ItemCommand(object sender, GridCommandEventArgs e)
        {
            #region Copy
            if (e.CommandName == "CopySelected")
            {
                mService = new monService.SrvCoreClient();
     
                List<int> idList = new List<int>();
     
                foreach (GridDataItem item in grArtList.Items)
                { //Går igenom varje rad i dgOrdersvar
                    CheckBox chk = (CheckBox)item.FindControl("chkCopy");
                    if (chk.Checked) //Känner av om Checkboxen är ikryssad (den ska med)
                    {
                        int rowID = int.Parse(item.GetDataKeyValue("koppl_id").ToString());
                        idList.Add(rowID);
                    }
                }
                Session.Remove("copyIDList");
                Session.Add("copyIDList", idList);
     
                string CopyUrl = "'admCopyPopup.aspx?type=" + Request.QueryString["type"].ToString() + "'";
     
                RadAjaxManager.GetCurrent(Page).ResponseScripts.Add(String.Format("OpenWindow(" + CopyUrl + ", " + "'winCopy'); return false;"));
     
            }
            #endregion
     
            #region delete
            if (e.CommandName == "deletePart")
            {
                GridNestedViewItem nestedRow = (GridNestedViewItem)e.Item;
                GridDataItem row = (GridDataItem)nestedRow.ParentItem;
     
                mService = new monService.SrvCoreClient();
                DataTable dtSend = mService.GetEmptyMonodbcTable(common.getSession(Session).id, "anp_bw_artkoppling");
     
                dtSend.Clear();
                DataRow rowToDelete = dtSend.NewRow();
                rowToDelete["id"] = Convert.ToInt32(row.GetDataKeyValue("koppl_id").ToString());
     
                try
                {
                    dtSend.Rows.Add(rowToDelete);
                    mService.ExecuteDbRequest(common.getSession(Session).id, "anp_bw_artkoppling", dtSend, monService.DbHandlerdb_request_type.Delete, "EN", 0);
                    grArtList.Rebind();
                }
                catch (Exception ex)
                {
                    Label lblError = new Label();
                    lblError.Text = "Unable to delete record. Reason: " + ex.Message;
                    lblError.ForeColor = System.Drawing.Color.Red;
                    grArtList.Controls.Add(lblError);
                    e.Canceled = true;
                }
            }
            #endregion
        }

  2. Viktor Tachev
    Admin
    Viktor Tachev avatar
    1488 posts

    Posted 23 Apr 2015 Link to this post

    Hi Christian,

    I tried to replicate the behavior on my end, however, I was unable to. I am attaching a sample project I used for testing.

    Please give the sample a try and let me know how it works for you. I would appreciate it if you can describe what should be changed in the sample in order to replicate the problematic behavior.


    Regards,
    Viktor Tachev
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top