Gridview not populating while using a While() structure. C# ASP.Net

后端 未结 6 1431
礼貌的吻别
礼貌的吻别 2021-01-22 18:46

I am having problems with this grid view. I am populating it with a query. However, it will not populate or even appear if I use a while(reader.Read()) structure. Without the

6条回答
  •  执念已碎
    2021-01-22 18:50

    I guest you have set datasource to myList instead myReader

    grdEvents.DataSource = myList;
    

    Edit: You need to add other column in your list object.

    while (myReader .Read ())
    {
    //myList-- Add other columns you need to display in the gridview
    //As I don't know the your Data Reader column, I can't give you exact mylist object
    
     myList.Add(new TicketInfo{TicketCost = Convert.ToDecimal(myReader["TicketCost"]),NumTickets = Convert.ToInt32(myReader["NumTickets"])  });
    }
    

提交回复
热议问题