tags:

views:

29

answers:

2

Hi All,

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

A: 

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

Braveyard
I have no problem with this , I have created this method and define the SelectMethod of my object data source and it is working correctly , the problem that I want to get the list of student back in some other function to do some processing
Amira Elsayed
A: 

Thank you All , 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();
}

Thanks in Advance

Amira Elsayed