i selected this method by objectdatasource in gridview , but the gridview appeared empty ![enter image description here][1]
[1]:gridview photo.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;
}
UPDATE - Try to make my answer more helpful
If you want to simply bind your data to a gridview, it is very easy to do it on the backend. Lets say you do it in the Page_Load method.
protected void Page_Load(object sender, eventArgs e){
var data = Item_Getall(); //Creates a list of items by calling your method.
gridView.DataSource = data; //assuming the ID of your gridview is "gridView". It might be something different.
gridView.DataBind(); //binds the data to your grid. If you have it set to auto populate, it should essentially list out every public property for each object in the list.
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.