Data source is an invalid type. It must be either an IListSource, IEnumerable, or IDataSource

后端 未结 3 1206
说谎
说谎 2021-01-14 16:28

Data source is an invalid type. It must be either an IListSource, IEnumerable, or IDataSource. The error is displayed when I bind the grid view

var list = d         


        
3条回答
  •  轮回少年
    2021-01-14 17:16

    In my testing page I make us of the following piece of code to display a list of different objects or just a single object in the same gridview.

       var data = bl.getAirlines();
       // If single object returned cast to List
       // Note that could be already a list of 1 item though!
        if (data.Count == 1)
        {
            var list = new List { data };               
            GridView1.DataSource = list;
        }
        else
         // Bind to list of items returned
            GridView1.DataSource = data;
    
        GridView1.DataBind();
    
    
    

    Hope it helps! It works for me :)

    提交回复
    热议问题