View photos by Repeater with sql server Using split

Asked

Viewed 67 times

0

I’m not able to upload the photos in repiter making a carousel coming from the data bank, I can not find anything on the web related to this problem follows the Cod ASPX Imoveldetail

              <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 Imovel 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 the information and Images are entered in 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 it can call the images in the reapeter?

1 answer

0

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

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

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

It is necessary to include using System.Linq; at the beginning of the page.

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

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

Browser other questions tagged

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