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 reco开发者_如何学Crds 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
精彩评论