user2962142 user2962142 - 1 year ago 68
ASP.NET (C#) Question

how to view data from generic collection to html page in

Sorry im new to i wanna view last 6 products in my table in a speicific way, i need each value in its own variable so this is what i did so far :

List<item> listid = new List<item>();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
item product = new item();
product.title = dr["product"].ToString();
product.desc = dr["des"].ToString();
product.price = dr["price"].ToString();
product.owner = dr["owner"].ToString();

with an "item" class with all those strings, the question is how do i view each value alone on the .aspx webpage ?

like if i wanted to view the third item price ?

Answer Source

You have a List of type "item", so you can loop through each item in the list and pull the properties, or get the third item in the list directly by it's index like so:

var singleItem = listid[2]; // This is the third item since list is 0-indexed
Console.WriteLine(singleItem.price); // This should return the item price
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download