简体   繁体   English

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

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

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