2

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

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

   public List<students> GetAllStudents()
   {
       // Here I'm retrieving a list of student from Database
   }
}

在 UI 控件 ascx

<asp:GridView ID="MyGrid" runat="server" 
              DataSourceID="MyDataSource" 
              OnRowCommand="MyGrid_RowCommand">
</asp:GridView>

<asp:ObjectDataSource ID="MyDataSource" runat="server" 
    TypeName="student"
    SelectMethod="GetAllStudents">

在 UI Control 代码后面

protected void MyGrid_RowCommand(object sender, GridViewCommandEventArgs e)
{
     // Here I want to get the list of students from my gridview
}

我想检索网格中显示的数据列表,以便能够检查列表中最后一个学生的年龄值

请尽快帮助我

提前致谢

4

2 回答 2

2

我找到了

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

protected void MyGrid_RowCommand(object sender, GridViewCommandEventArgs e)
{
     List<student> lst =(List<student>)MyDataSource.Select();
}
于 2010-10-11T14:46:49.310 回答
1

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

请查看这篇文章,它非常简洁易懂。

http://www.highoncoding.com/Articles/139_GridView_With_ObjectDataSource.aspx

于 2010-10-11T14:20:42.837 回答