I have some dropdownlists in a particular screen and whenever I get the value of the same, always comes the first value. What do I do to solve this, the dropdownlist in other pages work correctly and can select the value of them, this can not.
I'm setting the values of this dynamically, every time I go up a file in the server folder, I upgraded, filling it with a vector that has the name (in string) of all items in the directory. When I select a different value than what comes standard on it, quyando'll get to play her value in the database, is as if I had not selected anything. I've tried to solve autoPorsback true and false, and nothing in the page_load. How do I fix this? I have no errors in the code.
NOTE: The drop down list is loaded EVERY TIME I climb a new file, as I do not have it in the IsPostBack. Every time I climb a new file, I have a method MostraImagensCarrefadas()
that updates and populates the dropdownlist. This method gets the event of a button. I am not using update panel and nothing of the sort.
all my code for the component:
//aspx header
<%@ Page Title="" Language="C#" MasterPageFile="~/administrativo/MasterPage.master" EnableViewState="false" AutoEventWireup="true" CodeFile="cadastroImovel.aspx.cs" Inherits="administrativo_cadastroImovel" %>
//dropdownlist in aspx
<div class="span2">
<div>
<asp:DropDownList ID="ddlImgPrincipal" runat="server" Width="160px" AutoPostBack="false" OnSelectedIndexChanged="ddlImgPrincipal_SelectedIndexChanged">
</asp:DropDownList>
</div>
</div>
// Method page_load
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
}
}
//where I try to get the value of the dropdownlist
protected void btSalvar_Click(object sender, EventArgs e)
{
eImoveis imovel = new eImoveis();
imovel.area_total = txtArea.Text;
imovel.bairro = txtBairro.Text;
imovel.banheiro = txtBanheiro.Text;
imovel.cep = txtCep.Text;
imovel.cidade = ((System.Web.UI.WebControls.ListControl) (ddlCidade)).SelectedValue.ToString();
imovel.codcliente = ((System.Web.UI.WebControls.ListControl) (ddlProprietario)).SelectedValue.ToString();
imovel.codtipoimovel = ((System.Web.UI.WebControls.ListControl) (ddlCategoriaImovel)).SelectedValue.ToString();
imovel.complemento = txtComplemento.Text;
imovel.descricao = txtDescricao.Text;
imovel.garagem = txtVagasGaragem.Text;
imovel.nome = txtNome.Text;
imovel.numero = txtNúmero.Text;
imovel.quarto = txtQuartos.Text;
imovel.referencia = txtReferencia.Text;
imovel.rua = txtRua.Text;
//imovel.suite = sui
imovel.valor = txtValor.Text;
if (manImovel.Insere(imovel))
{
eImagens imagem = new eImagens();
manImagem manImg = new manImagem();
List<String> files = new manFile().getListFilesForDirectory(this, MAE.DIRETORIO_TEMP_IMG);
DataTable dt = manImovel.getLastID(imovel);
DataRow row = dt.NewRow();
String codigo = dt.Rows[0].ItemArray[0].ToString();
int tamanho = 0;
if (files != null)
{
foreach (String str in files)
{
imagem.cdImovel = codigo;
imagem.imagem = str;
if (ddlImgPrincipal.SelectedItem != null)
{
if (ddlImgPrincipal.SelectedItem.ToString() == str)
{
imagem.imagemPrincipal = "SIM";
}
}
if (manImg.Insere(imagem))
{
tamanho++;
}
//tamanho++;
}
}
if (tamanho == files.Count)
{
if (new manFile().CopiaTodosOsArquivos(this, MAE.DIRETORIO_TEMP_IMG, MAE.DIRETORIO_IMG))
{
if (new manFile().DeletaTodosArquivos(this, MAE.DIRETORIO_TEMP_IMG))
{
MontaLiteralCarrossel();
}
}
}
}
}
//Here I fill the dropdownlist
public void MostraImagensCarrefadas()
{
List<String> files = new manFile().getListFilesForDirectory(this, MAE.DIRETORIO_TEMP_IMG);
ddlImgPrincipal.Items.Clear();
if (files != null)
{
foreach (String item in files)
{
ddlImgPrincipal.Items.Add(new ListItem(item));
}
}
}