1.怎么让List集合进行调用并且查询数据 进行读取查询得到第一条数据
protected void gvCar_cbCarNumType_Init(object sender, EventArgs e)
{
ASPxComboBox cb = sender as ASPxComboBox;
List<DropdownCar> lsCars=dropdownBuilders.BuildCarDropdownListByCompany(sessionManager.GetSessionUser().CompanyId);
cb.DataSource = lsCars;
cb.DataBind();
DropdownCar car=lsCars.FirstOrDefault(); 进行读取查询得到第一条数据
if(car!=null){
cb.Value = car.CarId;
cb.Text = car.CarNum;
}
}
public List<DropdownCar> BuildCarDropdownListByCompany(int CompanyId)
{
List<DropdownCar> carDropdownList = new List<DropdownCar>();
carDropdownList = (from d in carDAL.GetCarsConciseByCompany(CompanyId).AsEnumerable()
orderby d["CarNum"]
select new DropdownCar
{
CarId = Convert.ToInt32(d["Id"]),
CarNum = d["CarNum"].ToString(),
}).ToList();
return carDropdownList;
}
测试
使用DataTable 进行for循环查询到的数据
if (CarNum.Equals("0"))
{
cb.Value = " ------------------------------------请选择------------------------------------ ";
DataTable dt = carServices.GetCarsConciseByCompany(sessionManager.GetSessionUser().CompanyId);
if (dt.Rows.Count > 0)
{
var dr = dt.Rows[0];
cb.Text = Convert.ToString(dr["CarNum"]);
cb.Value = Convert.ToString(dr["Id"]);
}
foreach (DataRow dr in dt.Rows)
{
string CarInfo = dr["CarNum"].ToString();
string CarId = Convert.ToString(dr["Id"]);
cb.Text = CarInfo;
cb.Value = CarId;
Console.WriteLine(CarId + ":" + CarInfo);
}
}