首页 > 解决方案 > Gridview 工具提示不限制列文本以设置字符数量

问题描述

我在我的 gridview 上设置了一个工具提示,仅在我的第二列中显示文本的前 30 个字符,但它不起作用。我错过了什么?

  protected void GridView4_RowDataBound (object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                ViewState["OrigData"] = e.Row.Cells[1].Text;
                if (e.Row.Cells[1].Text.Length >= 30)
                {
                    e.Row.Cells[1].Text = e.Row.Cells[0].Text.Substring(0, 30) + "...";
                    e.Row.Cells[1].ToolTip = ViewState["OrigData"].ToString();
                }
            }
        }

这是gridview的样子。我需要以“00000000000000000000000012464...等”开头的第二列仅显示前 30 个字符。

网格视图示例

标签: c#asp.netgridview

解决方案


推荐阅读