My Repeater does not render in the browser

Asked

Viewed 165 times

0

I created a Repeater and I can’t render it. When I inspect the object, it doesn’t appear. I took the code above it, called Analyze registration data and repeated after the Reset and can view, but the Reset does not. What could be wrong? Below the code from Analyze Registration 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 Rewinds in my project and none of them I have a Datasource like this, explicit as you are telling me to do. See this example that 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 on the list and popular my Peater, type, <%#Eval("Campo_1")%> I can guarantee that I have a Datasource there, without the need to clarify?

This is the method I fill in my Reset.

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;
            }
        }
  • You set the Datasource and gave Databind() on it? Check and comment.

  • I think that’s exactly what it is. The people in the O.R..

  • Where you are passing the data (list of items) to that your second "rptTitulares"?

  • So that’s what I’m talking about. I can’t see explicitly. What I have are methods returning values and getting caught on Asp.net with the Eval function()

  • @Fernando, I thought yes, it was bad. There really exists explicitly the Databind() on top of the Peater. I think I now managed to find the way.

  • I found it strange, because without data, there is no logic for the Repeater work, after all the concept of DataSource is data source, be it a list, a query (Cursor), etc.

Show 1 more comment

1 answer

1


As quoted in comments apparently what it lacks is to set the Datasource and apply a Databind().

You have to define a data source (Datasource) to the Repeater, then for each item of the list set in Datasource it will make an interaction (its working is like a for, where in each interaction it render a template).

And it’s also necessary that you give a Datadind(), to inform Repeater that 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 on ASP.net, via Datasourceid, here complete example (I 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 will be ignoring everyone, losing all the advantages of its use):

<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>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.