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

RadGrid and NestedViewTemplate

1 Answer 146 Views
Grid
This is a migrated thread and some comments may be shown as answers.
SMA SOFTWARE
Top achievements
Rank 1
SMA SOFTWARE asked on 29 Mar 2010, 03:09 PM
Hello,

I'm trying to do the RadGrid as is, in the example the following link: http://demos.telerik.com/aspnet-ajax/grid/examples/hierarchy/nestedviewtemplate/defaultcs.aspx,
and parts of binding within RadPageView are not getting visible, even while they datasources
met, could give me a help to resolve this issue, because the contents are not displayed in RadPageView. The following are the codes. Aspx and cs.


ASPX:

<%@ Page Title="" Language="C#" MasterPageFile="~/Protegidos/Administracao/GENTE_Adm.master"
    AutoEventWireup="true" CodeFile="LogOperacao.aspx.cs" Inherits="Protegidos_Log_LogOperacao" %>

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<asp:Content ID="Content1" ContentPlaceHolderID="cphSubConteudo" runat="Server">
    <style type="text/css">
        .viewWrap
        {
            padding: 15px;
            background: #2291b5 0 0 url(Img/bluegradient.gif) repeat-x;
        }
        .contactWrap
        {
            padding: 10px 15px 15px 15px;
            background: #fff;
            color: #333;
        }
        .contactWrap td
        {
            padding: 0 20px 0 0;
        }
        .contactWrap td td
        {
            padding: 3px 20px 3px 0;
        }
        .contactWrap img
        {
            border: 1px solid #05679d;
        }
    </style>
    <!-- content start -->
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="rgLogdado">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="rgLogdado" LoadingPanelID="RadAjaxLoadingPanel1" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" />
    <table width="99%" align="center">
        <tr>
            <td colspan="2">
                <div class="Titulo01">
                    Administração</div>
                <div class="Titulo02">
                    Log</div>
            </td>
        </tr>
        <tr>
            <td>
                <table width="100%" align="right">
                    <tr id="trMensagem" runat="server" visible="false">
                        <td valign="middle" style="background-color: #FFFFAA; height: 25px; width: 100%">
                            &nbsp;&nbsp;
                            <asp:Label ID="lblResultado" runat="server" Text="" Font-Names="Verdana" Font-Size="9"></asp:Label>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <div class="subTitulo_pagina">
                                Dados Log</div>
                            <div class="espaco">
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <table class="textoCZ_12B" width="99%">
                                <tr>
                                    <td style="width: 146px">
                                        Código do Prestador
                                    </td>
                                    <td style="width: 180px">
                                        <telerik:RadComboBox ID="rcbPrestador" runat="server">
                                        </telerik:RadComboBox>
                                        <asp:RequiredFieldValidator ID="rfvPrestador" runat="server" ControlToValidate="rcbPrestador"
                                            ErrorMessage="*" InitialValue="-- Selecione --" Text="*" ValidationGroup="vgLog"></asp:RequiredFieldValidator>
                                    </td>
                                    &nbsp&nbsp
                                    <td style="width: 81px">
                                        Usuário
                                    </td>
                                    <td style="width: 180px">
                                        <telerik:RadComboBox ID="rcbUsuario" runat="server">
                                        </telerik:RadComboBox>
                                        <asp:RequiredFieldValidator ID="rfvUsuario" runat="server" ControlToValidate="rcbUsuario"
                                            ErrorMessage="*" InitialValue="-- Selecione --" Text="*" ValidationGroup="vgLog"></asp:RequiredFieldValidator>
                                    </td>
                                </tr>
                                <tr>
                                    <td style="width: 146px">
                                        Data Inicial
                                    </td>
                                    &nbsp&nbsp
                                    <td style="width: 117px">
                                        <telerik:RadDatePicker ID="rdpDataAcaoInicio" runat="server" ShowPopupOnFocus="true"
                                            MinDate="01/01/1850" MaxDate="01/01/3000">
                                            <DateInput DateFormat="dd/MM/yyyy" EmptyMessage="dd/MM/aaaa">
                                            </DateInput>
                                        </telerik:RadDatePicker>
                                        <asp:RequiredFieldValidator ID="rfvDataAcao" runat="server" ControlToValidate="rdpDataAcaoInicio"
                                            ErrorMessage="*" Text="*" ValidationGroup="vgLog"></asp:RequiredFieldValidator>
                                    </td>
                                    <td style="width: 81px">
                                        Data Inicial
                                    </td>
                                    &nbsp&nbsp
                                    <td>
                                        <telerik:RadDatePicker ID="rdpDataAcaoFinal" runat="server" ShowPopupOnFocus="true"
                                            MinDate="01/01/1850" MaxDate="01/01/3000">
                                            <DateInput DateFormat="dd/MM/yyyy" EmptyMessage="dd/MM/aaaa">
                                            </DateInput>
                                        </telerik:RadDatePicker>
                                        <asp:RequiredFieldValidator ID="rfvDataAcaoFinal" runat="server" ControlToValidate="rdpDataAcaoFinal"
                                            ErrorMessage="*" Text="*" ValidationGroup="vgLog"></asp:RequiredFieldValidator>
                                    </td>
                                </tr>
                                <tr>
                                    <td style="width: 146px">
                                        Tipo da Ação
                                    </td>
                                    <td colspan="3">
                                        <telerik:RadComboBox ID="rcbTipoAcao" runat="server">
                                        </telerik:RadComboBox>
                                        <asp:RequiredFieldValidator ID="rfvTipoAcao" runat="server" ControlToValidate="rcbTipoAcao"
                                            ErrorMessage="*" InitialValue="-- Selecione --" Text="*" ValidationGroup="vgLog"></asp:RequiredFieldValidator>
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="6" align="right">
                                        <asp:Button ID="brnPesquisar" Text="Pesquisar" runat="server" OnClick="brnPesquisar_Click" />
                                        <asp:HiddenField ID="hdnTipoDado" runat="server" />
                                        <asp:HiddenField ID="hdnIdLog" runat="server" />
                                        <br />
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="6">
                                        <telerik:RadGrid ID="rgLogdado" runat="server" AllowPaging="True" Width="100%" Skin="Telerik"
                                            OnPreRender="rgLogdado_PreRender" OnItemCreated="rgLogdado_ItemCreated" OnItemCommand="rgLogdado_ItemCommand"
                                            AllowAutomaticInserts="false" ShowGroupPanel="true">
                                            <PagerStyle Mode="NumericPages" />
                                            <MasterTableView Width="100%" CommandItemDisplay="Top" PageSize="10" AutoGenerateColumns="false"
                                                DataKeyNames="IdLog">
                                                <Columns>
                                                    <telerik:GridBoundColumn UniqueName="IdLog" HeaderText="IdLog" DataField="IdLog"
                                                        Visible="false">
                                                    </telerik:GridBoundColumn>
                                                    <telerik:GridBoundColumn UniqueName="RazaSocialPatrocinador" HeaderText="Patrocinador"
                                                        DataField="RazaSocialPatrocinador" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left">
                                                    </telerik:GridBoundColumn>
                                                    <telerik:GridBoundColumn UniqueName="RazaoSocialPrestador" HeaderText="Prestador"
                                                        DataField="RazaoSocialPrestador" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left">
                                                    </telerik:GridBoundColumn>
                                                    <telerik:GridBoundColumn UniqueName="Login" HeaderText="Usuário" DataField="Login"
                                                        ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left" HeaderStyle-Width="150px">
                                                    </telerik:GridBoundColumn>
                                                    <telerik:GridBoundColumn UniqueName="TipoAcao" HeaderText="Ação" DataField="TipoAcao"
                                                        ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left" HeaderStyle-Width="100px">
                                                    </telerik:GridBoundColumn>
                                                    <telerik:GridBoundColumn UniqueName="DataAcao" HeaderText="Data" DataField="DataAcao"
                                                        ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left" HeaderStyle-Width="100px">
                                                    </telerik:GridBoundColumn>
                                                </Columns>
                                                <NestedViewTemplate>
                                                    <asp:Panel ID="NestedViewPanel" runat="server" CssClass="viewWrap">
                                                        <div class="contactWrap">
                                                            <fieldset style="padding: 10px;">
                                                                <legend style="padding: 5px;"><b>Log de Operações</b> </legend>
                                                                <table>
                                                                    <tr>
                                                                        <td>
                                                                            <telerik:RadTabStrip runat="server" ID="TabLog" MultiPageID="Multipage1" SelectedIndex="0">
                                                                                <Tabs>
                                                                                    <telerik:RadTab runat="server" Text="Dados Anteriores" PageViewID="PageView1">
                                                                                    </telerik:RadTab>
                                                                                    <telerik:RadTab runat="server" Text="Dados Atuais" PageViewID="PageView2">
                                                                                    </telerik:RadTab>
                                                                                    <telerik:RadTab runat="server" Text="Detalhes do Log" PageViewID="PageView3">
                                                                                    </telerik:RadTab>
                                                                                </Tabs>
                                                                            </telerik:RadTabStrip>
                                                                            <telerik:RadMultiPage runat="server" ID="Multipage1" SelectedIndex="0" RenderSelectedPageOnly="false">
                                                                                <telerik:RadPageView runat="server" ID="PageViewDadosAnteriores">
                                                                                    <telerik:RadGrid runat="server" ID="rgAnterior" OnNeedDataSource="rgAnterior_NeedDataSource"
                                                                                        ShowFooter="true" AllowSorting="true" EnableLinqExpressions="false">
                                                                                        <MasterTableView ShowHeader="true" AutoGenerateColumns="true">
                                                                                        </MasterTableView>
                                                                                    </telerik:RadGrid>
                                                                                </telerik:RadPageView>
                                                                                <telerik:RadPageView ID="PageViewDadosAtuais" runat="server">
                                                                                    <telerik:RadGrid runat="server" ID="rgAtual" ShowFooter="true" AllowSorting="true"
                                                                                        EnableLinqExpressions="false" OnNeedDataSource="rgAtual_NeedDataSource">
                                                                                        <MasterTableView ShowHeader="true" AutoGenerateColumns="true">
                                                                                        </MasterTableView>
                                                                                    </telerik:RadGrid>
                                                                                </telerik:RadPageView>
                                                                                <telerik:RadPageView runat="server" ID="PageViewDetalhes">
                                                                                </telerik:RadPageView>
                                                                            </telerik:RadMultiPage>
                                                                        </td>
                                                                    </tr>
                                                                </table>
                                                            </fieldset>
                                                        </div>
                                                    </asp:Panel>
                                                </NestedViewTemplate>
                                            </MasterTableView>
                                        </telerik:RadGrid>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
</asp:Content>


CS:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SMA.Log;
using SMA.Seguranca.DadosV2;
using SMA.GENTEv1;
using System.Data;
using System.Xml;
using System.IO;
using System.Text;
using System.Xml.Linq;
using SMA.Core;
using Telerik.Web.UI;

public partial class Protegidos_Log_LogOperacao : PageBase
{
    private LogOPeration logOperation;
    private List<LogOPeration> listLogOperation;
    private SMA.Seguranca.Usuario usuario;
    private Organizacao organizacao;

    private DataSet dsDadoAnterior;
    private DataTable dtDadoAnterior;

    private DataSet dsDadoAtual;
    private DataTable dtDadoAtual;

    private XElement xElementParse;
    private SMAXmlBuilder smaXmlBuilder;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            CarregarPrestador();
            CarregarUsuario();
            CarregarTipoAcao();
        }
    }

    private void CarregarTipoAcao()
    {
        SMA.Log.TipoAcao tipoAcao = new SMA.Log.TipoAcao();
        Util.BindDropDownlist(tipoAcao.SelectAll(), "descricao", "IdTipoAcao", true, ref rcbTipoAcao);
    }

    private void CarregarPrestador()
    {
        organizacao = new Organizacao();
        organizacao.IdOrganizacao = IdPatrocinador;
        Util.BindDropDownlist(organizacao.SelectPatrocinadorPrestador(), "RazaoSocial", "IdOrganizacao", true, ref this.rcbPrestador);
    }

    private void CarregarUsuario()
    {
        usuario = new SMA.Seguranca.Usuario();
        Util.BindDropDownlist(usuario.SelectAll(), "Login", "IdUsuario", true, ref this.rcbUsuario);
    }

    protected void brnPesquisar_Click(object sender, EventArgs e)
    {
        Page.Validate("vgLog");
        if (Page.IsValid)
        {
            SelecionarLog();
        }
    }

    private void SelecionarLog()
    {
        DateTime? dataOPeracao;

        logOperation = new LogOPeration();

        logOperation.IdPrestador = Convert.ToInt32(this.rcbPrestador.SelectedValue);
        logOperation.IdUsuario = Convert.ToInt32(this.rcbUsuario.SelectedValue);
        logOperation.IdTipoAcao = Convert.ToInt32(this.rcbTipoAcao.SelectedValue);

        dataOPeracao = this.rdpDataAcaoInicio.SelectedDate;
        logOperation.DataAcaoInicio = dataOPeracao.Value;

        dataOPeracao = this.rdpDataAcaoFinal.SelectedDate;
        logOperation.DataAcaoFinal = dataOPeracao.Value;

        listLogOperation = logOperation.SelectLog();
        logOperation.Dispose();

        rgLogdado.DataSource = listLogOperation;
        rgLogdado.DataBind();
    }

    protected void rgLogdado_PreRender(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            this.rgLogdado.MasterTableView.Rebind();
        }

        foreach (GridCommandItem cmditm in rgLogdado.MasterTableView.GetItems(GridItemType.CommandItem))
        {
            if (rgLogdado.Items.Count > 0)
            {
                Button btn1 = (Button)cmditm.FindControl("AddNewRecordButton");
                btn1.Visible = false;
                LinkButton lnkbtn1 = (LinkButton)cmditm.FindControl("InitInsertButton");
                lnkbtn1.Visible = false;
            }
        }
    }

    /// <summary>
    /// Pegar dados xml do log
    /// </summary>
    /// <param name="idLog">Código do log</param>
    /// <param name="tipoDado">Tipo de Dado -> 1= Dado Atual, 2 -> Dado Anterior</param>
    /// <returns>Dataset contendo os dados do xml</returns>
    private DataSet GetDataTableFromXml(int idLog, int tipoDado)
    {
        List<LogOPeration> listLogSelected;
        DataSet returnData = null;

        logOperation = new LogOPeration();
        logOperation.IdLog = idLog;
        listLogSelected = logOperation.SelectLogById();

        if (listLogSelected != null)
        {
            if (listLogSelected.Count > 0)
            {
                switch (tipoDado)
                {
                    case 1:
                        {
                            if (!string.IsNullOrEmpty(listLogSelected[0].DadoAtual))
                            {
                                dsDadoAtual = new DataSet();
                                dtDadoAtual = new DataTable();

                                xElementParse = XElement.Parse(listLogSelected[0].DadoAtual, LoadOptions.None);

                                smaXmlBuilder = new SMAXmlBuilder();
                                dtDadoAtual = smaXmlBuilder.XElementToDataTable(xElementParse);

                                dsDadoAtual.Tables.Add(dtDadoAtual);
                            }
                            else
                                dsDadoAtual = new DataSet();

                            returnData = dsDadoAtual;
                        }
                        break;
                    case 2:
                        {
                            if (!string.IsNullOrEmpty(listLogSelected[0].DadoAnterior))
                            {
                                dsDadoAnterior = new DataSet();
                                dtDadoAnterior = new DataTable();

                                xElementParse = XElement.Parse(listLogSelected[0].DadoAnterior, LoadOptions.None);

                                smaXmlBuilder = new SMAXmlBuilder();
                                dtDadoAnterior = smaXmlBuilder.XElementToDataTable(xElementParse);

                                dsDadoAnterior.Tables.Add(dtDadoAnterior);
                            }
                            else
                                dsDadoAnterior = new DataSet();

                            returnData = dsDadoAnterior;
                        }
                        break;
                }
            }
        }

        return returnData;
    }

    protected void rgLogdado_ItemCreated(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridNestedViewItem)
        {
            //e.Item.FindControl("InnerContainer").Visible = ((GridNestedViewItem)e.Item).ParentItem.Expanded;
        }
    }

    protected void rgLogdado_ItemCommand(object source, GridCommandEventArgs e)
    {
        DataSet dsBind = null;

        if (e.CommandName == RadGrid.ExpandCollapseCommandName)
        {
            this.hdnIdLog.Value = ((GridDataItem)e.Item).Cells[2].Text;

            Panel panelItems = (Panel)((GridDataItem)e.Item).ChildItem.FindControl("NestedViewPanel");
            if (panelItems != null)
            {
                panelItems.Visible = true;
                //!e.Item.Expanded;
            }
            //((GridDataItem)e.Item).ChildItem.FindControl("NestedViewPanel").Visible = true;
            //!e.Item.Expanded;
            //Preencher grid de dados anteriores
            RadGrid rgDadoAnterior = (RadGrid)((GridDataItem)e.Item).ChildItem.FindControl("NestedViewPanel").FindControl("rgAnterior");
            if (rgDadoAnterior != null)
            {
                if (!string.IsNullOrEmpty(((GridDataItem)e.Item).Cells[2].Text))
                {
                    dsBind = GetDataTableFromXml(Convert.ToInt32(((GridDataItem)e.Item).Cells[2].Text), 2);
                    if (dsBind != null)
                    {
                        if (dsBind.Tables.Count > 0)
                        {
                            rgDadoAnterior.MasterTableView.DataSource = dsBind;
                            rgDadoAnterior.DataBind();
                        }
                    }
                }
            }

            //Prencher dados atuais
            RadGrid rgDadoAtual = (RadGrid)((GridDataItem)e.Item).ChildItem.FindControl("NestedViewPanel").FindControl("rgAtual");
            if (rgDadoAtual != null)
            {
                if (!string.IsNullOrEmpty(((GridDataItem)e.Item).Cells[2].Text))
                {
                    dsBind = GetDataTableFromXml(Convert.ToInt32(((GridDataItem)e.Item).Cells[2].Text), 1);
                    if (dsBind != null)
                    {
                        if (dsBind.Tables.Count > 0)
                        {
                            rgDadoAtual.MasterTableView.DataSource = dsBind;
                            rgDadoAtual.DataBind();
                        }
                    }
                }
            }
        }
    }

    protected void rgAnterior_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
    {
        RadGrid rgLogAnterior = null;

        if (!e.IsFromDetailTable)
        {
            if (!string.IsNullOrEmpty(this.hdnIdLog.Value))
            {
                rgLogAnterior = (RadGrid)this.rgLogdado.FindControl("NestedViewPanel").FindControl("rgAnterior");
                if (rgLogAnterior != null)
                {
                    rgLogAnterior.DataBind();
                }
            }
        }
    }

    protected void rgAtual_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
    {
        RadGrid rgLogAtual = null;

        if (!e.IsFromDetailTable)
        {
            if (!string.IsNullOrEmpty(this.hdnIdLog.Value))
            {
                rgLogAtual = (RadGrid)this.rgLogdado.FindControl("NestedViewPanel").FindControl("rgAtual");
                if (rgLogAtual != null)
                {
                    rgLogAtual.DataBind();
                }
            }
        }
    }
}

Thanks,

Ivan Souza.











1 Answer, 1 is accepted

Sort by
0
Mira
Telerik team
answered on 01 Apr 2010, 12:35 PM
Hello,

I have followed your scenario and prepared a sample project for you implementing the desired functionality.
You can find it attached to this message.

If the issues persist, please open a formal support ticket and send us a sample runnable project demonstrating it. We will debug it locally and get back to you with our findings.

Regards,
Mira
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.
Tags
Grid
Asked by
SMA SOFTWARE
Top achievements
Rank 1
Answers by
Mira
Telerik team
Share this question
or