GridView 和 objectDataSource

发布于 2024-09-26 22:59:50 字数 850 浏览 3 评论 0原文

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

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

绾颜 2024-10-03 22:59:50

我发现

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

protected void MyGrid_RowCommand(object sender, GridViewCommandEventArgs e)
{
     List<student> lst =(List<student>)MyDataSource.Select();
}

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();
}
翻了热茶 2024-10-03 22:59:50

您应该定义 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文