ods_选定行数

发布于 2024-09-10 19:31:20 字数 438 浏览 2 评论 0原文

我有以下代码,它提供了绑定到对象数据源的 gridview 中的行数。

protected void odsProduct_Selected(object sender, ObjectDataSourceStatusEventArgs e)
        {
            lblHowManyRows.Text = ((List<tblProduct>)e.ReturnValue).Count.ToString();

迷人的。

但是,在对象数据源生成 gridview 输出之前,我将如何基本上进行相同的计数?

我想做的是让用户有机会检查在实际创建 gridview (绑定到对象数据源)之前将返回多少行。ods

中是否有某些内容,或者我应该编写另一个 linq 语句并将其绑定到那个?

为我的无知道歉

I have the following bit of code that gives me the number of rows in a gridview bound to an object data source.

protected void odsProduct_Selected(object sender, ObjectDataSourceStatusEventArgs e)
        {
            lblHowManyRows.Text = ((List<tblProduct>)e.ReturnValue).Count.ToString();

Lovely.

However, how would I go about essentially doing the same count but before the object data source produces the gridview output?

What I am trying to do is give the user the chance to check how many rows would be returned before they actually create the gridview (bound to the object data source)

Is there something that lies within the ods or should I just write another linq statement and bind it to that?

Apologies for my ignorance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

心的位置 2024-09-17 19:31:20

那么,您可以有一个如下所示的 OnSelecting 事件:

protected void OnSelecting(object sender, ObjectDataSourceSelectingEventArgs e)
    {
        if (lblHowManyRows.Text == string.Empty)
        {
            e.Cancel = true;
            lblHowManyRows.Text = [Linq statement here].Count().ToString();
        }
    }

第一次将标签设置为计数,并在下次检索数据。

下次 lblHowManyRows 不会为空,因此它将进入您的 odsProduct_Selected 方法:

        protected void odsProduct_Selected(object sender, ObjectDataSourceStatusEventArgs e)
    {
        lblHowManyRows.Text = string.Empty;
    }

清空标签,以便用户可以继续选择。这样,他们第一次单击时仅获得计数,下次单击时获得完整的网格范围。

如果是我,我很可能会通过 AJAX/webservice 检索完整的计数,而不进行回发或根本使用 gridview,但我不知道问题的完整上下文。

Well, you could have an OnSelecting event such as this:

protected void OnSelecting(object sender, ObjectDataSourceSelectingEventArgs e)
    {
        if (lblHowManyRows.Text == string.Empty)
        {
            e.Cancel = true;
            lblHowManyRows.Text = [Linq statement here].Count().ToString();
        }
    }

where it sets the label to the count the first time, and retrieves the data the next time.

The next time the lblHowManyRows won't be empty, so it'll make it to your odsProduct_Selected method:

        protected void odsProduct_Selected(object sender, ObjectDataSourceStatusEventArgs e)
    {
        lblHowManyRows.Text = string.Empty;
    }

Blank out the label so that the user can continue to select. This way the first time they click they get only the count and the next time they click they get the full grid bound.

If it were me, I'd most likely retrieve the complete count via AJAX/webservice without doing a postback or using the gridview at all, but I don't know the full context of the question.

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