Hello,
Again, can anyone tell me an example on how to bind all data rows to a gridview using a method of an object?
Jirr
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jean PaulPosted Jan 20, 2011, 4:58 AM
Then bind the list to the DataSource property of grid.
(make sure the object you are returning is a class and have properties - so that the grid can generate column headers dynamically)
Eg:
Place a datagridview control on a windows forms application - form and use the following code
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
IList list = new ArrayList();
list.Add(GetObject());
dataGridView1.DataSource = list;
}
private TestClass GetObject()
{
return new TestClass() { Id = 100 };
}
public class TestClass
{
public int Id
{
get;
set;
}
}
}
Jirr MeynorPosted Jan 20, 2011, 10:16 PM
@Sam - Sorry about the gridview thing. Yeah you're right it's supposed to be datagridview because I need it in windows application.
Bryian TanPosted Jan 20, 2011, 9:41 PM
Here is another good example
Bind ASP.NET GridView to a Custom Object or Collection with Paging and Sorting
Sam HobbsPosted Jan 20, 2011, 4:59 PM