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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Jean PaulRank #32 · 38.5K reputationPosted Jan 19, 2011, 11:58 PM EST
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;
}
}
}
Sam HobbsRank #107 · 20.5K reputationPosted Jan 20, 2011, 11:59 AM EST
Bryian TanRank #396 · 6.3K reputationPosted Jan 20, 2011, 4:41 PM EST
Here is another good example
Bind ASP.NET GridView to a Custom Object or Collection with Paging and Sorting
Jirr Meynor22 reputationPosted Jan 20, 2011, 5:16 PM EST
@Sam - Sorry about the gridview thing. Yeah you're right it's supposed to be datagridview because I need it in windows application.