繁体   English   中英

在asp.net代码后面知道GridView行高

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM