Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# GridView和objectDataSource_C#_Asp.net_Caching_Objectdatasource_Data Retrieval - Fatal编程技术网

C# GridView和objectDataSource

C# GridView和objectDataSource,c#,asp.net,caching,objectdatasource,data-retrieval,C#,Asp.net,Caching,Objectdatasource,Data Retrieval,我有一个网格视图,它绑定到一个对象数据源,从学生类型中选择数据 public class student { int id; string name; int age; public List<students> GetAllStudents() { // Here I'm retrieving a list of student from Database } } 我想检索网格中显示的数据列表,以便能够检查列表中最后一个学生的年

我有一个网格视图,它绑定到一个对象数据源,从学生类型中选择数据

public class student
{
   int id;
   string name;
   int age;

   public List<students> GetAllStudents()
   {
       // Here I'm retrieving a list of student from Database
   }
}
我想检索网格中显示的数据列表,以便能够检查列表中最后一个学生的年龄值

请尽快帮助我


提前感谢

您应该为CRUD定义方法并将它们绑定到ObjectDataSource

请检查这篇文章,它是非常整洁,易于理解

我找到了

我可以直接访问MyDataSource.Select()方法,然后我会得到一个对象列表

protected void MyGrid_RowCommand(object sender, GridViewCommandEventArgs e)
{
     List<student> lst =(List<student>)MyDataSource.Select();
}
受保护的void MyGrid_row命令(对象发送方,GridViewCommandEventArgs e)
{
List lst=(List)MyDataSource.Select();
}

到目前为止,您尝试了哪些代码?我已经在我的网格视图上定义了onrow命令,在此事件中,((GridView)sender).DataSourceObject.GetView(“DefaultView”),但我没有找到任何可以检索我的列表的东西。我对此没有问题,我已经创建了这个方法并定义了我的对象数据源的SelectMethod,它工作正常,问题是我想在其他函数中获取学生列表以进行一些处理
protected void MyGrid_RowCommand(object sender, GridViewCommandEventArgs e)
{
     // Here I want to get the list of students from my gridview
}
protected void MyGrid_RowCommand(object sender, GridViewCommandEventArgs e)
{
     List<student> lst =(List<student>)MyDataSource.Select();
}