Pregunta

I'm trying to bind a single row to a Telerik RadGridView, but I think this question might apply to any GridView control. Since this list only ever contains one item, it seems inefficient to bind to a "List", even though I know that List only has one item. However, when I try to just bind to a single item in my list, nothing happens. Nothing shows up on my grid, but I don't get an error in the debugger.

This works. GetObjects is a Dal method that returns a List.

List<MyObject> myObjects = MyDal.GetObjects(myID);
this.myGridView.DataSource = myObjects;

The following code does NOT work. GetObject is a Dal method that only returns the first element from a List.

MyObject myObject = MyDal.GetObject(myID);
this.myGridView.DataSource = myObject;
¿Fue útil?

Solución

I just tried your code but I bound it to object called class1 and it works so fine using this method:

List<MyObject> _list1=new List<MyObject>();
_list1.Add(MyDal.GetObject(myID));
RadGrid1.DataSource=_list1;
RadGrid1.DataBind();

the reason is Grid Should only be bound to IListSource, IEnumerable, or IDataSource.

Regards

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top