Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i get gridview row count

I am trying to get gvProducts row count.

I have tried the below code but it give insufficient result.

 protected void gvProducts_RowCommand(object sender, GridViewCommandEventArgs e)
   {

        string commandName = e.CommandName.ToString().Trim();
        GridViewRow row = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
        if (row.Controls.Count == 1)
        {
            //my code
        }
 }
like image 595
ayman Avatar asked Oct 02 '15 18:10

ayman


Video Answer


1 Answers

You want total rows in Gridview? Use Count property:

gvProducts.Rows.Count

Update:

To find the rows count of nested gridview, you can use the RowDataBound event of parent gridview:-

protected void gvProductsParent_RowCommand(object sender, GridViewCommandEventArgs e)
{
   if (e.Row.RowType == DataControlRowType.DataRow)
   {
        GridView gvProducts = (GridView)e.Row.FindControl("gvProducts ");
        int count = gvProducts.Rows.Count;
   }
}

Please note this event will fire for each row present in your parent gridview this the count will change according to each row.

like image 182
Rahul Singh Avatar answered Sep 30 '22 20:09

Rahul Singh