My DAL that does Select and saves it in type list
using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MySql.Data;
using MySql.Data.MySqlClient;
using Geax1.Model;
namespace Geax1.DAL
{
public class ListaVeiculosDAL
{
private static List<_Veiculos> lv = new List<_Veiculos>();
public static void ListaVeiulos(_Clientes obj)
{
using (var conn = new MySqlConnection("server=127.0.0.1;Database=xpto;User ID=root;Password='';"))
{
try
{
MySqlDataAdapter adapter = new MySqlDataAdapter();
adapter.SelectCommand = new MySqlCommand("SELECT * FROM tab_veiculo ORDER BY id;", conn);
DataSet dataset = new DataSet();
adapter.Fill(dataset);
foreach (DataRow linha in dataset.Tables[0].Rows)
{
_Veiculos veiculo = new _Veiculos();
veiculo.Modelo1 = Convert.ToString(linha["modelo"]);
veiculo.Placa1 = Convert.ToString(linha["placa"]);
veiculo.Quilometragem1 = Convert.ToString(linha["quilometragem"]);
veiculo.Cor1 = Convert.ToString(linha["cor"]);
veiculo.Chassi1 = Convert.ToString(linha["chassi"]);
veiculo.Quilometragem1 = Convert.ToString(linha["tipo"]);
lv.Add(veiculo);
}
}
catch (Exception e)
{
throw e;
}
}
}
public static List<_Veiculos> retornaVeiculo()
{
return lv;
}
}
}
Calling my method inside my GridView . However, running the page is blank, it returns no select value.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Geax1.DAL;
using Geax1.Model;
namespace Geax1.Views
{
public partial class ListagemVeiculos : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
GrdVeiculo.AutoGenerateColumns = true;
GrdVeiculo.DataSource = ListaVeiculosDAL.retornaVeiculo();
GrdVeiculo.DataBind();
}
}
}