【问题标题】:Limited size in grid view column(truncate string length)网格视图列中的大小有限(截断字符串长度)
【发布时间】:2015-03-18 21:21:46
【问题描述】:

这是我的网格视图编码,我希望基于菜单名称截断长度。

<asp:BoundField DataField="MenuName" HeaderText="MenuName" TruncateLegnth="6" />
 <asp:BoundField DataField="Url" HeaderText="Url" />
  <asp:BoundField DataField="Tooltip" HeaderText="Tooltip" />

之前我使用的是动态值集

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { int i = 0;

        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            foreach (TableCell cell in e.Row.Cells)
            {
                i++;
                string Word = cell.Text;


                if (cell.Text.Length > 5 && (i == 1))
                    cell.Text = cell.Text.Substring(0, 5) + "....";

                if (cell.Text.Length > 3 && (i == 3))
                    cell.Text = cell.Text.Substring(0, 3) + "....";
                if (cell.Text.Length > 6 && (i == 2))
                    cell.Text = cell.Text.Substring(0, 6) + "....";
                cell.ToolTip = Word;
            }
        }


    } 

现在我需要基于 TruncateLegnth 的列。

【问题讨论】:

    标签: c# asp.net gridview


    【解决方案1】:

    为什么不给你的单元格一个 CSS 类,并将文本溢出属性设置为省略号?

    .cell {
        white-space: nowrap; 
        overflow: hidden;
        text-overflow: ellipsis; 
    }
    

    http://www.w3schools.com/cssref/tryit.asp?filename=trycss3_text-overflow

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-03-12
      • 2017-06-13
      • 2016-01-17
      • 2011-10-02
      • 2014-08-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多