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
}
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With