NestedViewTemplate RadGrid not firing ItemCommand

12 posts, 0 answers
  1. Kate
    Kate avatar
    3 posts
    Member since:
    Nov 2008

    Posted 18 Mar 2010 Link to this post

    Hi Telerik,

    I am using a RadGrid with a NestedViewTemplate. Within that NestedViewTemplate is another RadGrid.
    All data is binding correctly using Advanced DataBinding techniques. My problem is the nested grid just will not fire the "ItemCommand" event.

    If I say add a button within the template this will fire correctly. It's just any commands sent from the inner grid that wont fire.

    I've tried adding an ItemCommand eventhandler directly to the inner grid but still nothing. So in the code below the "AddPayment" command fires as it's a button seperate from the grid. But no matter what I've tried (GridButtonCol, Button within a Template Col etc)
    no ItemCommand is fired for RadGrid: Payments.

    <telerik:RadGrid ID="InvoiceGrid" runat="server" >
        <MasterTableView Name="Master" AutoGenerateColumns="false" EditMode="EditForms" AllowPaging="true" ShowHeader="true" PageSize="10" DataKeyNames="InvoiceId">
            <NestedViewSettings>
                <ParentTableRelation><telerik:GridRelationFields DetailKeyField="InvoiceId" MasterKeyField="InvoiceId" /></ParentTableRelation>
            </NestedViewSettings>
            <NestedViewTemplate>          
               <fieldset style="padding:10px;">
                    <legend style="padding:5px;"><b><asp:Label runat="server" ID="InvoiceHeadings" Text="Invoice Payments"></asp:Label></b></legend>
                    <div id="InvoicePaymentsGrid" runat="server">
                    <asp:Button runat="server" ID="AddNewPayment" Text="Add Payment" CommandName="AddPayment" />
                     <telerik:RadGrid runat="server" ID="Payments">                     
                         <MasterTableView Name="PaymentsMaster" AutoGenerateColumns="false" AllowPaging="true" ShowHeader="true" PageSize="10" DataKeyNames="PaymentId">
                            <Columns>
                                <telerik:GridBoundColumn DataField="PaymentMethod" HeaderText="Payment Method">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="Comments" HeaderText="Comments"></telerik:GridBoundColumn>
                                <telerik:GridBoundColumn HeaderText="Payment Date" DataField="DateCreated" DataFormatString="{0:dd/MM/yyyy HH:mm}" UniqueName="DateCreated" ReadOnly="true">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn HeaderText="Amount" DataField="Amount" DataFormatString="{0:C}" UniqueName="Amount" ReadOnly="true">
                                </telerik:GridBoundColumn>
                                <telerik:GridTemplateColumn UniqueName="test">
                                    <ItemTemplate>
                                        <asp:Button runat="server" ID="Test" CommandName="Test" Text="Test" />
                                    </ItemTemplate>
                                </telerik:GridTemplateColumn>
                                <telerik:GridButtonColumn ButtonType="ImageButton" Text="Edit" UniqueName="EditOverride" CommandName="EditPayment">
                                    <HeaderStyle Width="20px" />
                                </telerik:GridButtonColumn>
                                <telerik:GridButtonColumn ButtonType="ImageButton" ConfirmText="Are you sure you want to delete this Invoice?" CommandName="DeletePayment" Text="Delete" UniqueName="Delete">
                                    <HeaderStyle Width="20px"></HeaderStyle>
                                </telerik:GridButtonColumn>
                            </Columns>                            
                        </MasterTableView>
                     </telerik:RadGrid>               
                     </div>            
                </fieldset>                       
            </NestedViewTemplate>        
            <Columns>
                <telerik:GridBoundColumn DataField="InvoiceNumber" HeaderText="Invoice Number" UniqueName="InvoiceNumber"></telerik:GridBoundColumn>  
                <telerik:GridBoundColumn HeaderText="Amount" DataField="Amount" DataFormatString="{0:C}" UniqueName="Amount" ReadOnly="true">
                </telerik:GridBoundColumn>
                <telerik:GridTemplateColumn HeaderText="Amount Paid" UniqueName="AmountPaid">
                    <ItemTemplate><asp:Label runat="server" ID="AmountPaidLabel" ></asp:Label></ItemTemplate>
                </telerik:GridTemplateColumn>          
                <telerik:GridTemplateColumn HeaderText="Subscription" UniqueName="Subscription">
                    <ItemTemplate><asp:Label runat="server" ID="SubscriptionLabel" ></asp:Label></ItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridBoundColumn HeaderText="Description" UniqueName="Description" DataField="Description">                
                </telerik:GridBoundColumn>  
                <telerik:GridBoundColumn HeaderText="Date Created" DataField="DateCreated" DataFormatString="{0:dd/MM/yyyy HH:mm}" UniqueName="DateCreated" ReadOnly="true">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn HeaderText="Date Updated" DataField="DateUpdated" DataFormatString="{0:dd/MM/yyyy HH:mm}" UniqueName="DateUpdated" ReadOnly="true">
                </telerik:GridBoundColumn>      
                <telerik:GridButtonColumn HeaderText="" ItemStyle-HorizontalAlign="Center" ButtonType="ImageButton" Text="View Invoice" UniqueName="ShowPdf" CommandName="ShowPdf"
                    HeaderStyle-Width="20px" ItemStyle-Width="20px" FooterStyle-Width="20px">
                </telerik:GridButtonColumn>
                <telerik:GridButtonColumn HeaderText="" ItemStyle-HorizontalAlign="Center" ButtonType="ImageButton" Text="Email Invoice" UniqueName="Email" CommandName="Email"
                    HeaderStyle-Width="20px" ItemStyle-Width="20px" FooterStyle-Width="20px">
                </telerik:GridButtonColumn>
                <telerik:GridButtonColumn ButtonType="ImageButton" Text="Edit" UniqueName="EditOverride" CommandName="Edit">
                    <HeaderStyle Width="20px" />
                </telerik:GridButtonColumn>
                <telerik:GridButtonColumn ButtonType="ImageButton" ConfirmText="Are you sure you want to delete this Invoice?" CommandName="Delete" Text="Delete" UniqueName="Delete">
                    <HeaderStyle Width="20px"></HeaderStyle>
                </telerik:GridButtonColumn>
            </Columns>     
        </MasterTableView>
    </telerik:RadGrid>

      private void InvoiceGrid_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
            {
                if (e.Item is GridNestedViewItem)
                {                              
                    RadGrid paymentsGrid = (RadGrid)e.Item.FindControl("Payments");
                    paymentsGrid.NeedDataSource += new GridNeedDataSourceEventHandler(PaymentsGrid_NeedDataSource);                
                }
                else if (e.Item is GridEditableItem && e.Item.IsInEditMode)
                {                
                    FormatGridEditForm(e);
                }
                else if (ControlHelper.IsItem(e.Item) && e.Item.OwnerTableView.Name == "Master")
                {
                    FormatInvoiceGridRow(e.Item);
                }
            }


            private void PaymentsGrid_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
            {
                RadGrid paymentsGrid = source as RadGrid;
                GridNestedViewItem nestedItem = paymentsGrid.NamingContainer as GridNestedViewItem;
                int invoiceId = Utilities.ToInt(nestedItem.ParentItem.GetDataKeyValue("InvoiceId"));
                List<Payment> payments = MembershipDataMethods.SelectPayments(invoiceId, true);
                paymentsGrid.DataSource = from p in payments orderby p.DateCreated descending select p;           
            }
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 19 Mar 2010 Link to this post

    Hi,

    Please try attaching the ItemCommand eent to the Payments grid from the InvoiceGrid ItemCreated event as shoen below:

     protected void InvoiceGrid_ItemCreated(object sender, GridItemEventArgs e) 
        { 
            if (e.Item is GridNestedViewItem) 
            { 
               GridNestedViewItem nestedViewItem = (GridNestedViewItem)e.Item; 
               RadGrid paymentsGrid=(RadGrid) nestedViewItem.FindControl("PaymentsGrid"); 
               paymentsGrid.ItemCommand += new GridCommandEventHandler(paymentsGrid_ItemCommand); 
            } 
        } 
     
        void paymentsGrid_ItemCommand(object source, GridCommandEventArgs e) 
        { 
            if (e.CommandName == "Edit"
            { 
            } 
        } 

    Do let me know if this was useful.

    Princy
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Kate
    Kate avatar
    3 posts
    Member since:
    Nov 2008

    Posted 22 Mar 2010 Link to this post

    Hi Princy,

    I have tried what you suggested but it made no difference. The ItemCommand event is still not being fired at all for the Payments grid.

    Do you have an example of a RadGrid with a NestedViewTemplate containing another RadGrid that fires an ItemCommand?

    Thanks
  5. Ken Kumar
    Ken Kumar avatar
    3 posts
    Member since:
    Dec 2009

    Posted 23 Mar 2010 Link to this post

    I am facing the same trouble with GridButtonColumn

     

    <telerik:GridButtonColumn ButtonType="ImageButton" Text="PDF" CommandName="View" ImageUrl="/publishingimages/adobe.jpg"

     

     

    HeaderStyle-Width="30px"/>

    When clicked on the imageButton it is not firing the itemCommand event.  I have two other columns as linkButton type and they are working fine.
    Any help?

     

  6. Veli
    Admin
    Veli avatar
    2002 posts

    Posted 08 Apr 2010 Link to this post

    Hello guys,

    The RadGrid hierarchy with templates demo demonstrates the exact same approach of firing commands from the grid inside the NestedViewTemplate of the parent grid. If you notice, you can sort the columns of the nested grid, which is effectively the same as firing a custom command from RadGrid.

    To attach an OnCommand handler to the nested grid, you can use:

    <telerik:RadGrid runat="server" ID="Payments"
        OnItemCommand="Payments_ItemCommand">
    </telerik:RadGrid>

    protected void Payments_ItemCommand(object sender, GridCommandEventArgs e)
    {
        if(e.CommandName == "Test")
        {
            //Test command is fired. Handle here.
        }
    }

    Check this out and let me know how it works for you.

    Regards,
    Veli
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  7. João Dias
    João Dias avatar
    3 posts
    Member since:
    Oct 2009

    Posted 14 Jul 2010 Link to this post

    Hi,

    I have the some problem... i have done what you suggest and no difference. The ItemCommand event is still not being fired when i click on the GridNestedViewItem. When i click on the GridNestedViewItem, the ItemCommand is fired, but on the parent grid.

    What i wanna do is -> select the parent item, when gridnesteditem has been selected.

    Any suggestion? Thanks.

    Urbano

    Here is my code:

    protected void RgEventoItems_ItemCreated(object sender, GridItemEventArgs e)
            {
                if (e.Item is GridNestedViewItem)
                {
                    GridNestedViewItem nestedViewItem = (GridNestedViewItem)e.Item;
                    RadGrid EIO = (RadGrid)nestedViewItem.FindControl("RgItemsObjectos");
                    EIO.ItemCommand += new GridCommandEventHandler(EIO_ItemCommand);
                }
            }

     protected void EIO_ItemCommand(object sender, GridCommandEventArgs e)
            {
                RadAjaxManager1.ResponseScripts.Add(@"alert('" + "EIO_ItemCommand" + "', 330, 210);");
       //   I never get this message
            }

    <telerik:RadAjaxPanel ID="RadAjaxPanel1" LoadingPanelID="RadAjaxLoadingPanel1" runat="server">
                                           <telerik:RadGrid ID="RgEventoItems" runat="server" OnItemDataBound="RgEventoItems_ItemDataBound"
                                             OnPageIndexChanged="RgEventoItems_PageIndexChanged" OnItemCreated="RgEventoItems_ItemCreated"
                                            AutoGenerateColumns="False" GridLines="None" AllowPaging="true" AllowSorting="True"
                                            Width="100%" OnPreRender="RgEventoItems_PreRender" AllowMultiRowSelection="true">
                                            <MasterTableView DataKeyNames="CodigoItem,CodigoPreco,Preco,ControlarPreco,Vagas,ControlarVagas,DescricaoPt" EditMode="EditForms"
                                                AllowPaging="true" GroupLoadMode="Server" AllowMultiRowSelection="true">
                                                <NestedViewTemplate>
                                                    <asp:Panel runat="server" ID="InnerContainer" CssClass="viewWrap">
                                                        <asp:Label ID="LblCodigoItem" runat="server" Visible="false"></asp:Label>
                                                        <telerik:RadGrid runat="server" ID="RgItemsObjectos" AutoGenerateColumns="false"
                                                            OnItemDataBound="RgItemsObjectos_ItemDataBound" OnItemCommand="RgItemsObjectos_ItemCommand"
                                                            OnPageIndexChanged="RgItemsObjectos_PageIndexChanged" AllowMultiRowSelection="true">
                                                            <MasterTableView DataKeyNames="Codigo, CodigoEvItem, CodigoPreco,Preco, TipoInscricao,ControlarPreco,Vagas,ControlarVagas,DescricaoPt" EditMode="EditForms"
                                                                AllowPaging="true" AllowMultiRowSelection="true">
                                                                <Columns>
                                                                    <telerik:GridBoundColumn DataField="Obrigatorio" HeaderText="Obrigatorio" ReadOnly="True"
                                                                        Visible="False" UniqueName="Obrigatorio">
                                                                    </telerik:GridBoundColumn>
                                                                    <telerik:GridBoundColumn DataField="SelectEnabled" HeaderText="SelectEnabled" ReadOnly="True"
                                                                        Visible="False" UniqueName="SelectEnabled">
                                                                    </telerik:GridBoundColumn>
                                                                    <telerik:GridClientSelectColumn UniqueName="ClientSelectColumn" >
                                                                        <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="30px" />
                                                                        <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="30px" />
                                                                    </telerik:GridClientSelectColumn>
                                                                    <telerik:GridBoundColumn DataField="Codigo" Visible="false" HeaderText="Cod"
                                                                        UniqueName="Codigo">
                                                                        <FooterStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="30px" />
                                                                        <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="30px" />
                                                                        <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="30px" />
                                                                    </telerik:GridBoundColumn>
                                                                    <telerik:GridTemplateColumn DataField="DescricaoPt" HeaderText="Descrição"
                                                                        UniqueName="DescricaoPt">
                                                                        <EditItemTemplate>
                                                                            <asp:TextBox ID="TxtDescricaoPt" runat="server" Text='<%# Bind("DescricaoPt") %>'
                                                                                Width="90%"></asp:TextBox>
                                                                            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TxtDescricaoPt"
                                                                                ErrorMessage="(*)"></asp:RequiredFieldValidator>
                                                                        </EditItemTemplate>
                                                                        <ItemTemplate>
                                                                            <asp:Label ID="LblDescricao" runat="server" Text='<%# Eval("DescricaoPt") %>'></asp:Label>
                                                                        </ItemTemplate>
                                                                        <FooterStyle HorizontalAlign="Left" VerticalAlign="Middle" />
                                                                        <HeaderStyle HorizontalAlign="Left" VerticalAlign="Middle" />
                                                                        <ItemStyle HorizontalAlign="Left" VerticalAlign="Middle" />
                                                                    </telerik:GridTemplateColumn>
                                                                    <telerik:GridTemplateColumn HeaderText="Datas" UniqueName="Datas">
                                                                        <ItemTemplate>
                                                                            <div align="left" style="vertical-align:middle">
                                                                                <asp:Label Visible='<%# Eval("MostrarDataInicioFim") %>' ID="LblDatasInicioFim" runat="server"
                                                                                    Text="Datas de Início e de Fim: " Width="200px"></asp:Label>
                                                                                <telerik:RadDatePicker Width="90px" Visible='<%# Eval("MostrarDataInicioFim") %>' ID="RDateInicio"
                                                                                    Enabled='<%# Eval("ObterResposta") %>'  AutoPostBack="true" runat="server" DbSelectedDate='<%# Eval("DataHoraInicio") %>'>
                                                                                </telerik:RadDatePicker>
                                                                                <telerik:RadDatePicker Width="90px" Visible='<%# Eval("MostrarDataInicioFim") %>'  ID="RDateFim"
                                                                                    Enabled='<%# Eval("ObterResposta") %>' AutoPostBack="true" runat="server" DbSelectedDate='<%# Eval("DataHoraFim") %>'>
                                                                                </telerik:RadDatePicker>
                                                                                <asp:Label ID="LblDataLimite" Visible='<%# Eval("MostrarDataLimite") %>' runat="server"
                                                                                    Text="Data Limite: " Width="200px"></asp:Label>
                                                                                <telerik:RadDatePicker Width="90px" ID="RDateLimite" Visible='<%# Eval("MostrarDataLimite") %>'
                                                                                    Enabled='<%# Eval("ObterRespostaLimite") %>' runat="server" DbSelectedDate='<%# Eval("DataLimite") %>'>
                                                                                </telerik:RadDatePicker>
                                                                            </div>
                                                                        </ItemTemplate>
                                                                        <FooterStyle HorizontalAlign="Left" VerticalAlign="Middle" Width="207px" />
                                                                        <HeaderStyle HorizontalAlign="Left" VerticalAlign="Middle" Width="207px" />
                                                                        <ItemStyle HorizontalAlign="Left" VerticalAlign="Middle" Width="207px" />
                                                                    </telerik:GridTemplateColumn>
                                                                    <telerik:GridTemplateColumn DataField="Vagas" HeaderText="Vagas" SortExpression="Vagas"
                                                                        UniqueName="Vagas">
                                                                        <ItemTemplate>
                                                                            &nbsp;<asp:Label ID="LblVagas" runat="server" Visible='<%# Eval("MostrarVagas") %>'
                                                                                Text='<%# Eval("VagasFalsas") %>'></asp:Label>
                                                                        </ItemTemplate>
                                                                        <FooterStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="30px" />
                                                                        <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="30px" />
                                                                        <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="30px" />
                                                                    </telerik:GridTemplateColumn>
                                                                    <telerik:GridTemplateColumn DataField="Preco" HeaderText="Preço" SortExpression="Preco"
                                                                        UniqueName="Preco">
                                                                        <ItemTemplate>
                                                                            <asp:Label ID="LblPreco" runat="server" Text='<%# String.Format(CultureInfo.GetCultureInfo("pt-PT"), "{0:C}",Eval("Preco"))%>'></asp:Label>
                                                                        </ItemTemplate>
                                                                        <FooterStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="55px" />
                                                                        <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="55px" />
                                                                        <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="55px" />
                                                                    </telerik:GridTemplateColumn>
                                                                    <telerik:GridTemplateColumn UniqueName="TemplateColumn" HeaderText="Obs.">
                                                                        <ItemTemplate>
                                                                            <asp:ImageButton ID="ImageButton1" CommandName="Obs" Visible='<%# Eval("MostrarObservacoes") %>' CommandArgument = '<%# Eval("ObservacoesPt") %>' runat="server" ImageUrl="~/Images/Botoes/BotaoInformacao_21.png" />
                                                                        </ItemTemplate>
                                                                        <FooterStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="25px" />
                                                                        <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="25px" />
                                                                        <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="25px" />
                                                                    </telerik:GridTemplateColumn>
                                                                </Columns>
                                                            </MasterTableView>
                                                            <PagerStyle Mode="Slider"></PagerStyle>
                                                            <ClientSettings EnableRowHoverStyle="true">
                                                                <Selecting AllowRowSelect="True" />
                                                            </ClientSettings>
                                                            <FilterMenu>
                                                                <CollapseAnimation Duration="200" Type="OutQuint" />
                                                            </FilterMenu>
                                                        </telerik:RadGrid>
                                                    </asp:Panel>
                                                </NestedViewTemplate>
                                                <Columns>
                                                    <telerik:GridBoundColumn DataField="Obrigatorio" HeaderText="Obrigatorio" ReadOnly="True"
                                                        Visible="False" UniqueName="Obrigatorio">
                                                    </telerik:GridBoundColumn>
                                                    <telerik:GridClientSelectColumn UniqueName="ClientSelectColumn">
                                                        <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="30px" />
                                                        <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="30px" />
                                                    </telerik:GridClientSelectColumn>
                                                    <telerik:GridBoundColumn DataField="CodigoItem"  Visible="false" HeaderText="Cod" ReadOnly="True" UniqueName="CodigoItem">
                                                        <FooterStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="30px" />
                                                        <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="30px" />
                                                        <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="30px" />
                                                    </telerik:GridBoundColumn>
                                                    <telerik:GridTemplateColumn DataField="DescricaoPt" HeaderText="Descrição" UniqueName="DescricaoPt">
                                                        <EditItemTemplate>
                                                            <asp:TextBox ID="TxtDescricaoPt" runat="server" Text='<%# Bind("DescricaoPt") %>'
                                                                Width="90%"></asp:TextBox>
                                                            <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="TxtDescricaoPt"
                                                                ErrorMessage="(*)"></asp:RequiredFieldValidator>
                                                        </EditItemTemplate>
                                                        <ItemTemplate>
                                                            <asp:Label ID="LblDescricao" runat="server" Text='<%# Eval("DescricaoPt") %>'></asp:Label>
                                                        </ItemTemplate>
                                                        <FooterStyle HorizontalAlign="Left" VerticalAlign="Middle" />
                                                        <HeaderStyle HorizontalAlign="Left" VerticalAlign="Middle" />
                                                        <ItemStyle HorizontalAlign="Left" VerticalAlign="Middle" />
                                                    </telerik:GridTemplateColumn>
                                                    <telerik:GridTemplateColumn HeaderText="Datas" UniqueName="Datas">
                                                        <ItemTemplate>
                                                            <div align="left">
                                                                <asp:Label Visible='<%# Eval("DatasVisiveis") %>' ID="LblDatasInicioFim" runat="server"
                                                                    Text="Datas de Início e de Fim: "></asp:Label>
                                                            </div>
                                                            <div align="left">
                                                                <telerik:RadDatePicker Width="90px" Visible='<%# Eval("DatasVisiveis") %>' ID="RDateInicio" Enabled='<%# Eval("ObterResposta") %>'
                                                                    runat="server" AutoPostBack="true" DbSelectedDate='<%# Eval("DataInicial") %>'>
                                                                </telerik:RadDatePicker>
                                                                &nbsp;
                                                                <telerik:RadDatePicker Width="90px" Visible='<%# Eval("DatasVisiveis") %>' ID="RDateFim" Enabled='<%# Eval("ObterResposta") %>'
                                                                    runat="server" AutoPostBack="true" DbSelectedDate='<%# Eval("DataFinal") %>'>
                                                                </telerik:RadDatePicker>
                                                            </div>
                                                        </ItemTemplate>
                                                        <FooterStyle HorizontalAlign="Left" VerticalAlign="Middle" Width="207px" />
                                                        <HeaderStyle HorizontalAlign="Left" VerticalAlign="Middle" Width="207px" />
                                                        <ItemStyle HorizontalAlign="Left" VerticalAlign="Middle" Width="207px" />
                                                    </telerik:GridTemplateColumn>
                                                    <telerik:GridTemplateColumn DataField="Vagas" HeaderText="Vagas" SortExpression="Vagas"
                                                        UniqueName="Vagas">
                                                        <ItemTemplate>
                                                            &nbsp;<asp:Label ID="LblVagas" runat="server" Visible='<%# Eval("MostrarVagas") %>' Text='<%# Eval("VagasFalsas") %>'></asp:Label>
                                                        </ItemTemplate>
                                                        <FooterStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="30px" />
                                                        <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="30px" />
                                                        <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="30px" />
                                                    </telerik:GridTemplateColumn>
                                                    <telerik:GridTemplateColumn DataField="Preco" HeaderText="Preço" UniqueName="Preco">
                                                        <ItemTemplate>
                                                            <asp:Label ID="LblPreco" runat="server" Text='<%# String.Format(CultureInfo.GetCultureInfo("pt-PT"), "{0:C}",Eval("Preco")) %>'></asp:Label>
                                                        </ItemTemplate>
                                                        <FooterStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="55px" />
                                                        <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="55px" />
                                                        <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="55px" />
                                                    </telerik:GridTemplateColumn>
                                                    <telerik:GridTemplateColumn UniqueName="TemplateColumn" HeaderText="Obs.">
                                                        <ItemTemplate>
                                                            <asp:ImageButton ID="ImageButton1" CommandName="Obs" Visible='<%# Eval("MostrarObservacoes") %>' CommandArgument = '<%# Eval("Observacoes") %>' runat="server" ImageUrl="~/Images/Botoes/BotaoInformacao_21.png" />
                                                        </ItemTemplate>
                                                        <FooterStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="25px" />
                                                        <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="25px" />
                                                        <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="25px" />
                                                    </telerik:GridTemplateColumn>
                                                    <telerik:GridCheckBoxColumn DataType="System.Boolean" DataField="ControlarPreco" HeaderText="ControlarPreco"
                                                        SortExpression="ControlarPreco" UniqueName="ControlarPreco" Visible="false">
                                                        <FooterStyle HorizontalAlign="Center" VerticalAlign="Middle"/>
                                                        <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle"/>
                                                        <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle"/>
                                                    </telerik:GridCheckBoxColumn>
                                                    <telerik:GridCheckBoxColumn DataType="System.Boolean" DataField="DatasVisiveis" HeaderText="DatasVisiveis"
                                                        SortExpression="DatasVisiveis" UniqueName="DatasVisiveis" Visible="false">
                                                        <FooterStyle HorizontalAlign="Center" VerticalAlign="Middle"/>
                                                        <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle"/>
                                                        <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle"/>
                                                    </telerik:GridCheckBoxColumn>
                                                </Columns>
                                            </MasterTableView>
                                            <ClientSettings EnableRowHoverStyle="false" EnablePostBackOnRowClick="true">
                                                <ClientEvents OnRowClick="" />
                                                <Selecting AllowRowSelect="True" UseClientSelectColumnOnly="true" />
                                            </ClientSettings>
                                            <PagerStyle Mode="Slider"></PagerStyle>
                                            <FilterMenu>
                                                <CollapseAnimation Duration="200" Type="OutQuint" />
                                            </FilterMenu>
                                        </telerik:RadGrid>
                                        </telerik:RadAjaxPanel>




  8. Veli
    Admin
    Veli avatar
    2002 posts

    Posted 15 Jul 2010 Link to this post

    Hi João,

    Expanding an item from the parent grid would, naturally, fire the parent grid's ItemCommand event, as it is a command that is initiated by the parent grid item. It is not related to the nested item.

    If you need to select the item that is expanding to show its child item, you need to handle the parent grid's ItemCommand event:

    protected void RgEventoItems_ItemCommand(object sender, GridCommandEventArgs e)
    {
        if(e.CommandName == RadGrid.ExpandCollapseCommandName)
        {
            e.Item.Selected = !e.Item.Expanded;
        }
    }

    The above command handler will select the parent grid item that is expanded. You can note I am using the parent grid's ItemCommand event.

    Greetings,
    Veli
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  9. João Dias
    João Dias avatar
    3 posts
    Member since:
    Oct 2009

    Posted 15 Jul 2010 Link to this post

    Hi again

    What you suggest don't resolve my problem...

    If i click (mouse) the row on the parend grid i have the event ItemCommand event of the parent grid (that's ok), but if i click on row of the child grid, why i still get the ItemCommand event of the parend grid? i should get the ItemCommand event of the child grid, no?

    What i need is: if i click (<telerik:GridClientSelectColumn UniqueName="ClientSelectColumn" >) a row on the child grid (inside a NestedViewTemplate) i have always the row  on the parend grid seleted too.

    Thanks,

    Urbano


  10. Veli
    Admin
    Veli avatar
    2002 posts

    Posted 19 Jul 2010 Link to this post

    Hello João,

    When commands are initiated from the inner RadGrid, only the inner RadGrid's ItemCommand event should be fired. I cannot reproduce the scenario you are describing, i.e. parent RadGrid's ItemCommand event fired on child grid's command. Can you give me exact steps how to reproduce this?

    On the other hand, if you want a selected row on the child grid to automatically select a parent item, you can implement this logic both on the client and the server.

    For the client-side approach, you can use the nested RadGrid's OnRowSelected client event:

    <ClientEvents OnRowSelected="childGridRowSelected" />

    In the event handler, we find the parent data row element and select it:

    function childGridRowSelected(sender, args)
    {
        var parentNestedRow = Telerik.Web.UI.Grid.GetFirstParentByTagName(sender.get_element(), "tr")
        var parentTable = $find(Telerik.Web.UI.Grid.GetFirstParentByTagName(parentNestedRow, "table").id);
        var parentDataRow = parentNestedRow.previousSibling;
     
        parentTable.selectItem(parentDataRow)
    }

    The server side approach is similar, only we use the SelectedIndexChanged server event of the nested grid:

    protected void RadGrid2_SelectedIndexChanged(object sender, EventArgs e)
    {
        RadGrid RadGrid2  = (RadGrid)sender;
        if (RadGrid2.SelectedItems.Count > 0)
        {
            GridNestedViewItem nestedItem = (GridNestedViewItem)RadGrid2.NamingContainer;
            nestedItem.ParentItem.Selected = true;
        }
    }

    Attached is a sample page demonstrating this approach. You can also note the 2 grid's ItemCommand events do not mix.

    Greetings,
    Veli
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  11. Jerry T.
    Jerry T. avatar
    118 posts
    Member since:
    Jul 2012

    Posted 03 Nov 2010 Link to this post

    Veli,

    You wrote that "When commands are initiated from the inner RadGrid, only the inner RadGrid's ItemCommand event should be fired. I cannot reproduce the scenario you are describing, i.e. parent RadGrid's ItemCommand event fired on child grid's command"

    If that is the case, then why have I been told (via a support ticket) that it's by design for RadGrid events to bubble up?

    I have a similar situation where I have a RadGrid with a NestedViewTemplate and in there are various ASP controls and some nested RadGrids. The user clicks the outer RadGrid to expand that row to reveal the template. If they click it again, it collapses that row. Fine, that works ok.  But, once the outer grid is clicked and expanded, clicking on a particular RadGrid that offers functionality to the user then the outer RadGrid collapses afterward as its ItemCommand event has been fired.

    The nested RadGrid works ok...I have a client-side event to fire to ensure the row is selected (or else I'm losing the SelectedValues on postback) and the ItemCommand event fires for the nested grid in order to Delete a row if a user clicks the Delete button but, after that, the outer RadGrid's ItemCommand even then fires as if I'd clicked on the outer grid, which I didn't!

    This must be corrected.

    Jerry

  12. Veli
    Admin
    Veli avatar
    2002 posts

    Posted 04 Nov 2010 Link to this post

    Hi Jerry T.,

    This behavior is most probably due to the fact that the nested view of the parent grid is rendered in a grid item itself. So, if you handled the client-side OnRowClick event of the parent grid, it will be fired for the nested view item too. This means that any click inside the nested item on any control that you may have will fire the parent item's click event. If you fire an item command from this event immediately, this may explain why you get the parent grid's ItemCommand fire on the server too. Effectively, you will have to prevent postbacks from clicks that originate inside the nested items of the parent grid.

    Veli
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  13. Jerry T.
    Jerry T. avatar
    118 posts
    Member since:
    Jul 2012

    Posted 04 Nov 2010 Link to this post

    Veli,

    That's a difficult thing to accomplish, especially when one wants to do various operations on a nested grid. This would have been much easier had I known from the start but I would still like to see the NestedViewTemplate's events be separate from the outer grid.  I've worked up a solution for the functionality I need (in support ticket 362548).

    I'm going to see how this will all work in an ItemTemplate, which is perhaps how I should have gone in the first place but the NestedViewTemplate seemed a good choice after doing some research.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017