displaying photos by Repeater with sql server Using split

0

I can not load the photos in the repiter by making a car from the data bank, I can not find anything on the web related to this problem follow the cod         ASPX ImovelDetails

              <section class="slider-container">
        <ul id="slider" class="slider-wrapper">
            <li class="slide-current">
                <asp:Repeater ID="RptImg" runat="server">
                    <ItemTemplate>
                        <asp:Image ID="Fotos" runat="server" ImageUrl='<%# Container.DataItem  %>' />
                    </ItemTemplate>
                </asp:Repeater>
            </li>
          </ul>
        <div class="shadow">
        </div>
        <ul id="slider-controls" class="slider-controls"></ul>
    </section>

CS Property Detail

      private void carregarInformacoes()
    {
        string[] filesindirectory = Directory.GetFiles(Server.MapPath("~/Imovel/"));
        List<ListItem> images= new List<ListItem>();
        foreach (string item in filesindirectory)
        {
        }
       RptImg.DataSource = images;
        RptImg.DataBind();

        int codigoImovel = 0;
        int.TryParse(Request.QueryString["IdImovel"], out codigoImovel);

        _imovelBo = new ImovelBo();
        var imovel = _imovelBo.ObterDetalhe(codigoImovel);

        if (imovel != null)
        {
            lblDescricao.Text = imovel.Obs;
            lblOperacao.Text = imovel.DescricaoOperacao;
            lblCidade.Text = imovel.DescricaoCidade;
            lblLocalizacao.Text = imovel.DescricaoLoc;
            lblTipoImovel.Text = imovel.DescricaoTipo;
            lblQtDormitorios.Text = imovel.QntQuarto.ToString();
            lblValor.Text = imovel.Valor.ToString("#,##0.00");
        }
    }

where information and Images are inserted into the database

          protected void btnSalvarImovel_Click(object sender, EventArgs e)

    {
        if (fuFotos.HasFile == false)
            lblImovel.Text = "Por favor selecione uma foto!";
        else
        {
            List<string> nomeFoto = new List<string> ();
            var arquivos = fuFotos.PostedFiles;
            foreach (var arquivo in arquivos)
            {
                string nomeArquivo = arquivo.FileName;
                fuFotos.PostedFile.SaveAs(Server.MapPath("~") + "/Imovel/" + nomeArquivo);
                nomeFoto.Add(nomeArquivo);
            }

            string comandoSQL = string.Format("INSERT INTO Imovel Values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}')",
                ddlCidade.SelectedItem.Value, ddlLocalizacao.SelectedItem.Value, ddlOperacao.SelectedItem.Value, ddlTipoImovel.SelectedItem.Value,
                txtTitulo.Text, txtObservacao.Text, txtValor.Text, txtQtdQuartos.Text, string.Join(",", nomeFoto));

            lblImovel.Text = "Imóvel cadastrado com sucesso!";
 try
            {
                conexaoSQL.Open();
                int teste = new SqlCommand(comandoSQL, conexaoSQL).ExecuteNonQuery();
            }
            finally
            {
                conexaoSQL.Close();
            }

What could be done so that I can call the images in the reapeter?

    
asked by anonymous 11.10.2016 / 14:16

1 answer

0

In the carregarInformacoes() method you are loading the full path values into an array, then you are creating a List of ListItem , which you are not loading, and then calling that list.

Instead of killing yourself doing all this, what you can do is call the array as the DataSource of the repeater.

RptImg.DataSource = filesindirectory.Select(x=> new{ Value = x }).ToList();

You must include using System.Linq; at the top of the page.

The reason to load this way is that the String object contains only one attribute, which is Length , to show the value of the variable it is necessary to do this, where an anonymous object with an attribute is created. value).

Instead of putting <%# Container.DataItem %> , put <%# Eval("Value") %>

    
17.10.2016 / 19:33