【发布时间】: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 的列。
【问题讨论】: