[英]Know the gridview row height in asp.net code behind
我有一个GridView
并使用DataSet
将其Bind
。 并将Gridview
Height
设置为autoHeight;
假设我的GridView
有3行,绑定后我想获取每行的行高。
我知道我可以通过RowHeight
动态设置RowHeight
GridView1.RowStyle.Height = 40;
但我想要像我这样的东西
int height=GridView1.Rows[0].Height;
我可以使用for
或any .....管理上述代码的逻辑
如果不想使用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.