问题
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
}
}
回答1:
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.
来源:https://stackoverflow.com/questions/32913837/how-can-i-get-gridview-row-count