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

后端 未结 3 1207
说谎
说谎 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:28

    You are returning a single object from GetEmployeebyName method and binding that to the GridViewEmployee, thats why it is giving error.

    You can change it like

    var empInfo = dal.GetEmployeebyName(name);
    var list = new List{empInfo};
    
    //or you can do this 
    //var list = new List();
    //list.Add(empInfo);
    
    GridViewEmployee.DataSource = list;
    GridViewEmployee.DataBind();
    

    DataSource must be a type of collection as the exception is stating ( It must be either an IListSource, IEnumerable, or IDataSource)

提交回复
热议问题