【发布时间】:2014-04-01 14:05:34
【问题描述】:
我在 gridview 中通过 objectdatasource 选择了这个方法,但是 gridview 显示为空 ![在此处输入图片说明][1]
[1]:gridview 照片.jpg
public List<Item> Item_Getall()
{
List<Item> data = new List<Item>();
SqlCommand cmd = new SqlCommand("c_get_all_item",oo.conn);
cmd.CommandType = CommandType.StoredProcedure;
oo.conn.Open();
SqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
data.Add(new Item());
{
Name_id = (rdr["item_name_id_pk"].ToString());
Name_arabic = (rdr["item_name_arabic"].ToString());
Component_english = (rdr["item_componant"].ToString());
Component_arabic = (rdr["item_componant_arabic"].ToString());
Price = float.Parse(rdr["item_price"].ToString());
Image = (rdr["item_image"].ToString());
Category = (rdr["item_category_name_id_fk"].ToString());
}
}
oo.conn.Close();
return data;
}
【问题讨论】:
-
试试
data.Add(new Item(){/*Your asignment code*/}); -
是的,就是这样。上面列出的代码实际上不会编译,但我假设他的代码不同,因为他说 gridview 不显示。