[英]How can i get gridview row count
我想獲取gvProducts
行數。
我嘗試了以下代碼,但結果不足。
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
}
}
你想要Gridview中的總行數? 使用Count
屬性:
gvProducts.Rows.Count
更新:
要查找嵌套gridview的行數,可以使用父gridview的RowDataBound
事件: -
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;
}
}
請注意,此事件將針對您的父網格視圖中的每一行觸發,此count
將根據每一行進行更改。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.