Reputation: 9414
I have a grid view that bounded to an object data source that select data from type of student
public class student
{
int id;
string name;
int age;
public List<students> GetAllStudents()
{
// Here I'm retrieving a list of student from Database
}
}
In the UI Control ascx
<asp:GridView ID="MyGrid" runat="server"
DataSourceID="MyDataSource"
OnRowCommand="MyGrid_RowCommand">
</asp:GridView>
<asp:ObjectDataSource ID="MyDataSource" runat="server"
TypeName="student"
SelectMethod="GetAllStudents">
In the UI Control code behind
protected void MyGrid_RowCommand(object sender, GridViewCommandEventArgs e)
{
// Here I want to get the list of students from my gridview
}
I want to retrieve the list of data that shown in the Grid to be able to check on the age value of last student in the list
please help me as soon as you can
Thanks in Advance
Upvotes: 2
Views: 871
Reputation: 9414
I have found it
I can access MyDataSource.Select() method directly and I will get a list of my objects
protected void MyGrid_RowCommand(object sender, GridViewCommandEventArgs e)
{
List<student> lst =(List<student>)MyDataSource.Select();
}
Upvotes: 2
Reputation: 81831
You should define methods for CRUD and bind them to ObjectDataSource.
Please check this article, it is very neat and easy to understand.
http://www.highoncoding.com/Articles/139_GridView_With_ObjectDataSource.aspx
Upvotes: 1