我有一个 GridView ,它绑定(bind)到一个对象数据源,该数据源从学生类型中选择数据
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
}
我想检索网格中显示的数据列表,以便能够检查列表中最后一个学生的年龄值
请尽快帮助我
提前致谢
最佳答案
我找到了
我可以直接访问 MyDataSource.Select() 方法,我将获得我的对象列表
protected void MyGrid_RowCommand(object sender, GridViewCommandEventArgs e)
{
List<student> lst =(List<student>)MyDataSource.Select();
}
关于c# - GridView 和 objectDataSource,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3907016/