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

后端 未结 6 1434
礼貌的吻别
礼貌的吻别 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 19:13

    How about this:

    using (myConnection)
    {
       myConnection.Open();
       DataSet ds = myCommand.ExecuteDataSet();
    
       //Binds listbox
       grdEvents.DataSource = ds;
       grdEvents.DataBind();                    
    }
    ForEach (DataRow dr in ds.tables[0].rows)
        myList.Add(new TicketInfo{TicketCost = Convert.ToDecimal(myReader["TicketCost"]),NumTickets = Convert.ToInt32(myReader["NumTickets"])  });  
    

提交回复
热议问题