简体   繁体   中英

How Can I get grid.rows.count once the button been clicked?

I have tried to used the following code under the aspx.cs file

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Test
{
    public partial class pgTest : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            lblResult.Text = grid.Rows.Count.ToString();
        }
    }
}

But somehow this is always not get the gird rows count for me in the 1st clicked on the button, but then it will show up in the 2nd clicked on the button.

Exmaple: If I manage to found 5 records in the 1st clicked, but then it will not show 5 on the screen until I clicked the button the 2nd time.

Does anyone know how can I solve this issue? how can I do it will only display the rows count on real time?

Put that line of code in the button's click event handler instead of Page_Load.

    protected void Button1_Click(object sender, EventArgs e)
    {
        lblResult.Text = grid.Rows.Count.ToString();
    }

where Button1_Click would be the event handler for your button's click event.

Since you want to do it real time... I think you should use javascript

Take a look at this question for GridView Row Count using Javascript

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM