[英]Know the gridview row height in asp.net code behind
I have a GridView
and using DataSet
to Bind
that. 我有一个
GridView
并使用DataSet
将其Bind
。 And Gridview
Height
set to autoHeight; 并将
Gridview
Height
设置为autoHeight;
Suppose I have 3 rows in My GridView
, After bind I want to fetch the row height of each row. 假设我的
GridView
有3行,绑定后我想获取每行的行高。
I know that I can set the RowHeight
dynamically by 我知道我可以通过
RowHeight
动态设置RowHeight
GridView1.RowStyle.Height = 40;
But I want somthing like my be 但我想要像我这样的东西
int height=GridView1.Rows[0].Height;
I can manage my logic of the above code using for
or any..... 我可以使用
for
或any .....管理上述代码的逻辑
If you don't want to use a foreach
loop, then you can use a RowDataBound
event to find the height of each row. 如果不想使用
foreach
循环,则可以使用RowDataBound
事件查找每行的高度。
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack) {
ViewState["rowHeightList"] = new List<decimal>();
}
}
if (e.Row.RowType == DataControlRowType.DataRow) {
decimal currentRowHeight = Convert.ToDecimal(e.Row.Height);
List<decimal> rowHeightList = (List<decimal>)ViewState["rowHeightList"];
rowHeightList.Add(currentRowHeight);
ViewState["rowHeightList"] = rowHeightList;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.