我如何获取GridView行数 [英] How can i get gridview row count
本文介绍了我如何获取GridView行数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试获取gvProducts
行计数.
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
}
}
推荐答案
您想要Gridview中的总行数吗?使用Count
属性:
You want total rows in Gridview? Use Count
property:
gvProducts.Rows.Count
更新:
要查找嵌套gridview的行数,可以使用父gridview的RowDataBound
事件:-
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;
}
}
请注意,此事件将针对父网格视图中显示的每一行触发,count
会根据每一行而变化.
Please note this event will fire for each row present in your parent gridview this the count
will change according to each row.
这篇关于我如何获取GridView行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文