GridView 和 objectDataSource
我有一个网格视图,它绑定到一个对象数据源,该数据源从学生类型中选择数据
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 控件代码中,
protected void MyGrid_RowCommand(object sender, GridViewCommandEventArgs e)
{
// Here I want to get the list of students from my gridview
}
我想检索网格中显示的数据列表,以便能够检查列表中最后一个学生的年龄值,
请尽快帮助我
提前致谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我发现
我可以直接访问 MyDataSource.Select() 方法,我将获得我的对象列表
I have found it
I can access MyDataSource.Select() method directly and I will get a list of my objects
您应该定义 CRUD 方法并将它们绑定到 ObjectDataSource。
请查看这篇文章,它非常简洁且易于理解。
http://www.highoncoding.com/Articles/139_GridView_With_ObjectDataSource.aspx
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