My repeater does not render in browser

0

I created a repeater and I can not render it. When I inspect the object, it does not appear. I took the code above it, called Analyze cadastral data and repeat after the repeater and I can see, but the repeater does not. What could be wrong? Below is the code from Analyze cadastral data:

<div class="boxAprovacao">
        <h2>Analisar dados cadastrais</h2>
        <asp:HiddenField ID="hdfCdPendencia" runat="server" />
        <asp:RadioButtonList ID="rblIcAprovado" runat="server" RepeatDirection="Horizontal">
            <asp:ListItem Text="Aprovar" Value="1"></asp:ListItem>
            <asp:ListItem Text="Reprovar" Value="0"></asp:ListItem>     
        </asp:RadioButtonList>
        <asp:TextBox ID="txtParecerDadosCadastrais" TextMode="MultiLine" runat="server" CssClass="parecerAnalista" />
        <asp:HiddenField ID="hdfCdUsuario" runat="server" />

        <asp:Repeater ID="rptHistoricoAnalises" runat="server" OnItemDataBound="rptHistoricoAnalises_ItemDataBound">
            <HeaderTemplate>
            <h3>Histórico de análises</h3>
            <dl>    
            </HeaderTemplate>

            <ItemTemplate>
            <dt>
                Por:
                <asp:Label Text="ANA LUCIA ALVES MARTINS" ID="lblHistAnaNmAnalista" runat="server" /><br />
                Em: <asp:Label Text="03/12/2014" ID="lblHistAnaData" runat="server" /> - <asp:Label Text="10:19" ID="lblHistAnaHorario" runat="server" />
            </dt>
            <dd>
                <asp:Label Text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque bibendum diam augue, ut varius lectus luctus a. Sed finibus fringilla nibh. Quisque orci erat, iaculis quis neque vitae, maximus vehicula tortor. Praesent luctus venenatis venenatis. Nullam non lacus orci. Vivamus convallis hendrerit urna, vel facilisis sapien semper non." ID="lblHistAnaParacerAnalista" runat="server" />
            </dd>
            </ItemTemplate>

            <FooterTemplate>
            </dl>
            </FooterTemplate>
        </asp:Repeater>
</div>
So the whole question is because I have several repeaters in my project and none of them I have a DataSource so explicit, as you are telling me to do. See this example I have here in my project of a repeater that works and has nothing so explicit.

<asp:Repeater ID="rptTitulares" runat="server" 
            onitemcommand="rptTitulares_ItemCommand" 
            OnItemDataBound="rptTitulares_ItemDataBound">
                <HeaderTemplate>
                    <table cellpadding="0" cellspacing="0" width="970px">
                        <thead>
                            <tr>
                                <th>&nbsp;</th>
                                <th>&nbsp;</th>
                                <th class="nameSize">Nome</th>
                                <th>Tipo</th>
                                <th>E-mail</th>
                                <th>Data Cadastro</th>
                            </tr>    
                        </thead>    
                </HeaderTemplate>
                <ItemTemplate>
                        <tbody>
                            <tr>
                                <td>
                                    <asp:LinkButton Text="Excluir" ID="lkbExcluirTitular" runat="server" OnClientClick="return confirm('Tem certeza que deseja excluir o Titular selecionado ?');"/>
                                </td>
                                <td>
                                    <asp:LinkButton Text="Exibir ficha"  ID="lkbExibirFicha" runat="server" />
                                    <asp:HiddenField ID="CdPessoa" Value='<%# Eval("CdPessoa")%>' runat="server" />
                                </td>
                                <td><asp:Label ID="lblNomeTitular" Text='<%# Eval("NmPessoa")%>' runat="server" /></td>
                                <td><asp:Label ID="lblTipoPessoa" Text='<%# Eval("NmTipoPessoa")%>' runat="server" /></td>
                                <td><asp:Label ID="lblEmail" Text='<%# Eval("DsEmail")%>' runat="server" /></td>
                                <td><asp:Label ID="lblDtExpiraCadastro" Text='<%# Eval("DtExpiraCadastro")%>' runat="server" /></td>
                            </tr>
                        </tbody>
                </ItemTemplate>
                <FooterTemplate>
                    </table>
                </FooterTemplate>
            </asp:Repeater>

I ask the following question. If I have a method that returns me a list and picks up each item from the list and popular my repeater, type, <% # Eval ("Field_1")% > can I guarantee that I have a DataSource there, without the need to make it explicit?

It is in this method that I fill in my repeater.

private void PreencherTitluarAvalista(List<ENTSPTitularesAvalistas> palstPessoas)
        {
            //Declarações
            List<ENTSPTitularesAvalistas> vlstTitular = null;
            List<ENTSPTitularesAvalistas> vlstAvalista = null;

            try
            {
                //Instâncias e Inicializações
                vlstTitular = new List<ENTSPTitularesAvalistas>();
                vlstAvalista = new List<ENTSPTitularesAvalistas>();

                //Desenvolvimento
                if (palstPessoas != null)
                {
                    for (int i = 0; i < palstPessoas.Count; i++)
                    {
                        if (palstPessoas[i].CdFuncaoPessoa == 1)
                        {
                            vlstTitular.Add(palstPessoas[i]);
                        }
                        else
                        {
                            vlstAvalista.Add(palstPessoas[i]);
                        }
                    }
                }

                if (vlstTitular.Count > 0)
                {
                    rptTitulares.DataSource = vlstTitular;
                    rptTitulares.DataBind();
                }
                else
                {
                    rptTitulares.DataSource = null;
                    rptTitulares.DataBind();
                }

                if (vlstAvalista.Count > 0)
                {
                    rptAvalistas.DataSource = vlstAvalista;
                    rptAvalistas.DataBind();
                }
                else
                {
                    rptAvalistas.DataSource = null;
                    rptAvalistas.DataBind();
                }

                switch (int.Parse(cmbCdTipoProcesso.SelectedValue))
                {
                    case 1:

                        pnlTitulares.Visible = true;
                        pnlNovoTitutlar.Visible = false;


                        pnlAvalistas.Visible = true;
                        pnlNovoAvalista.Visible = false;

                        break;

                    case 2:
                        pnlTitulares.Visible = true;
                        pnlNovoTitutlar.Visible = false;

                        pnlAvalistas.Visible = true;
                        pnlNovoAvalista.Visible = false;

                        break;

                    case 3:
                        pnlTitulares.Visible = true;
                        pnlNovoTitutlar.Visible = false;

                        pnlAvalistas.Visible = true;
                        pnlNovoAvalista.Visible = false;
                        break;

                    case 4:
                        pnlTitulares.Visible = true;
                        pnlNovoTitutlar.Visible = false;

                        pnlAvalistas.Visible = true;
                        pnlNovoAvalista.Visible = false;
                        break;
                }
            }
            catch
            {
                throw;
            }
        }
    
asked by anonymous 14.01.2015 / 18:35

1 answer

1

As quoted in the comments Apparently what you lack is setting the DataSource , and apply a DataBind () .

You have to define a data source ( DataSource ) to the Repeater , then for each list item set in DataSource it will make an interaction (its operation is like a for, where in every interaction it renders a template).

And you also need a DataDind () , to inform Repeater that the DataSource data has been updated.

In C # you can do something similar to this (Recommend) :

protected void Page_Load(object sender, EventArgs e)
{
    if(!IsPostBack)
    {
         rptHistoricoAnalises.DataSource = fonteDados.BuscarHistoricoAnalises();
         rptHistoricoAnalises.DataBind();
    }
}

Or in ASP.net, via DataSourceID , Here complete example (Do not advise, you lose control over the connection, not to mention that if you work with layers like: Dao / Repository, Domain, for example, you are ignoring everyone, losing all the advantages of using it) :

<asp:repeater id="Repeater1"       
        datasourceid="SqlDataSource1"
        runat="server">

        <headertemplate>
          <table border="1">
            <tr>
              <td><b>Product ID</b></td>
              <td><b>Product Name</b></td>
            </tr>
        </headertemplate>

        <itemtemplate>
          <tr>
            <td> <%# Eval("ProductID") %> </td>
            <td> <%# Eval("ProductName") %> </td>
          </tr>
        </itemtemplate>

        <footertemplate>
          </table>
        </footertemplate>
      </asp:repeater>

            <asp:sqldatasource id="SqlDataSource1"          
            connectionstring="<%$ ConnectionStrings:NorthWindConnection%>" 
        selectcommand="SELECT ProductID, ProductName FROM [Products] Where ProductID <= 10"
        runat="server">
      </asp:sqldatasource>
    
15.01.2015 / 11:57