1
I have the following dropdownlist where in the first person chooses whether to rent or sell immovable.
The consultation in the bank is being done as follows:
public List<Imovel> ObterCasaOperacao(string codigoOperacao)
{
try
{
string sql = "SELECT i.CodImovel, i.Titulo, i.Foto, o.IdOp FROM Imovel i inner join Operacao o on o.IdOp = i.IdOp";
List<string> parametros = new List<string>();
if (!string.IsNullOrEmpty(codigoOperacao))
parametros.Add("o.IdOp = " + codigoOperacao);
if (parametros.Count > 0)
sql += " where " + string.Join(" and ", parametros.ToArray());
var command = new SqlCommand(sql, Conexao.connection);
Conexao.connection.Open();
var reader = command.ExecuteReader();
var imoveis = new List<Imovel>();
while (reader.Read())
{
var imovel = new Imovel();
imovel.CodImovel = Convert.ToInt32(reader["CodImovel"]);
imovel.IdOp = Convert.ToInt32(reader["IdOp"]);
imovel.Titulo = reader["Titulo"].ToString();
string[] fotos = reader["Foto"].ToString().Split(',');
if (fotos.Length > 0)
{
imovel.Foto = string.Format("/ImageHandler.ashx?h=300&w=700&code={0}&file={1}", reader["CodImovel"], fotos.First());
}
imoveis.Add(imovel);
}
return imoveis;
}
catch (Exception)
{
throw;
}
finally
{
Conexao.connection.Close();
}
}
It passes to this function at BLL:
public List<Imovel> ObterCasaOperacao(string codigoOperacao)
{
_ImovelDao = new ImovelDao();
return _ImovelDao.ObterCasaOperacao(codigoOperacao);
}
And load the result on this repeater
, on the search result page.
private ImovelBo _imovelBo;
protected void Page_Load(object sender, EventArgs e)
{
CarregarImoveisNoRepeater();
}
private void CarregarImoveisNoRepeater()
{
string codigoOperacao = Request.QueryString["codigoOperacao"];
_imovelBo = new ImovelBo();
rptResult.DataSource = _imovelBo.ObterCasaOperacao(codigoOperacao);
rptResult.DataBind();
}
So far so good, I know I have to make a query for each dropdownlist, the problem is only being in separating it in the search button
protected void BntPesquisar_Click(object sender, EventArgs e)
{
Response.Redirect(string.Format("~/Painel/ResultadoBusca.aspx?codigoOperacao={0}", ddlOperacao.SelectedValue));
}
I would like to know how I could put a validation,(for example; if else ou switch case ou foreach
), so you can pick up each item.
For example: if I selected Operation and nothing else, it only brings the operation if to select city and anything else it brings the city that I selected and if to select several it brings also.
Thanks man, you helped a lot.
– Thais Ferreira