如果显示一列的内容很多不想完全显示用省略号显示怎么做啊???
不如有一列“主题”下面有一条记录的主题很长“我爱中国天安门”,我想显示“我爱中国...”
怎么做啊???
不如有一列“主题”下面有一条记录的主题很长“我爱中国天安门”,我想显示“我爱中国...”
怎么做啊???
解决方案 »
- DataGridView全选时有一行没选上
- Oracle 11g与ODAC的版本问题
- 关于c#窗体progressbar控件用法
- 求助:c#编写的应用程序运行时要安装Microsoft .NET Framework SDK 吗?
- 急急急~~~如何得到datagrid当前选择的行的各列的值(winform)
- C# 如何 使用CORBR与C++通信有人做过吗,跪求
- 怎么把查询到的数据写入xsd里的表?
- WPF中的路径动画物体的碰撞检测
- 向各位高手请教一道C#题
- C#中怎样在一个form掉用另一个form
- winform tabControl 控件的tab 里添加 背景图,进度条
- 急急急!!!一个web用户控件怎么调用两个不同的web用户控件?
public string Myleft(string str, int _int)
{
str = mycommon.MyLeftFunction(mycommon.NoHTML(str), _int).ToString();
return str;
}
/// <summary>
/// 截短字串的函数
/// </summary>
/// <param name="mText">要加工的字串</param>
/// <param name="byteCount">长度</param>
/// <returns>被加工过的字串</returns>
public string MyLeftFunction(string mText, int byteCount)
{
if (byteCount < 1) return mText; if (System.Text.Encoding.Default.GetByteCount(mText) <= byteCount)
{
return mText;
}
else
{
byte[] txtBytes = System.Text.Encoding.Default.GetBytes(mText);
byte[] newBytes = new byte[byteCount - 4]; for (int i = 0; i < byteCount - 4; i++)
newBytes[i] = txtBytes[i]; return System.Text.Encoding.Default.GetString(newBytes) + "...";
}
}页面中
<%#Myleft(Eval("Name").ToString(),10) %>
后面的数字就是你想要显示的位数了
{
if(e.Item.ItemType==ListItemType.Item || e.Item.ItemType==ListItemType.AlternatingItem)
{
string i = e.Row.Cells[2].Text;
if (i.Length > 4)
{
e.Row.Cells[2].Text = i.Substring(0, 4) + "...";
}
}
}
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType==ListItemType.Item || e.Item.ItemType==ListItemType.AlternatingItem)
{
string i = e.Item.Cells[2].Text;
if (i.Length > 4)
{
e.Item.Cells[2].Text = i.Substring(0, 4) + "...";
}
}
}