请问一些datagrid中的item的text过长,比如我只想显示width=200px,“中华人民共”这几个字正好200px的宽度,但是超过这个宽度就以...显示,如“中华人民共和国”就显示为“中华人民共...”
请问怎么做呢?
请问怎么做呢?
解决方案 »
- 为什么我这一句会有问题呢?不能取出gridView那一行的值
- 怎么会报错啊<%#Eval("Id") %>作为脚本方法的参数怎么会报错啊!
- 救救我啊..不能在托下去了,我找不到答案...
- 最近我们头儿让我做一个在线客服系统我想知道一下做这个系统会用到哪些技术,有免费源码的更好了
- 上传文件到数据库的过程中遇见了问题,小弟请教大家!
- AJAX如何用session
- Checkbox 如何控制checkboxlist?
- 紧急求教一个问题,在线等待
- asp.net新闻内容分页 在线等
- ********ActiveReport的用法?及如何打印图表?********
- TreeView树形结构的使用
- 菜鸟问题,回答正确马上结贴,在线等。
ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
If e.Item.Cells(0).Text.Length > 26 Then
e.Item.Cells(0).Attributes.Add("Title", e.Item.Cells(0).Text)
e.Item.Cells(0).Text = e.Item.Cells(0).Text.Substring(0, 26) + "…"
End If
e.Item.Cells(1).Text = Format(System.Convert.ToDateTime(e.Item.Cells(1).Text),_
"yyyy年M月d日 h点m分s秒")
End If
End Sub
{
if(e.Item.ItemType==ListItemType.EditItem)
{
for (int i = 0;i<16;i++)
{
TextBox textBox = (TextBox)e.Item.Cells[i].Controls[0];
textBox.Width = 200%;
}
}
}
然后在后台写方法,实现截断字符串
前台<%#getString((string)(DataBinder.Eval(Container.DataItem,"title")),38)%>
后台: protected string getString(string StringInput,int StringLength)
{
if(StringInput==""||StringInput==null)
return "";
string tempTitle="";
if(StringInput.Length>StringLength)
tempTitle = StringInput.Substring(0,StringLength)+"...";
else if(StringInput.Length==StringLength)
tempTitle = StringInput;
else
{
for(int i=0;i<StringLength-StringInput.Length;i++)
{
StringInput = StringInput+" ";
tempTitle=StringInput;
}
}
return tempTitle;
}
将一个汉字长度看作1,一个英文字母长度也是1...........有什么函数能将一个汉字长度看作2的,英文一个才是1 ?汉字占的位置可是英文字母的两倍啊~
if(buf.Length > 30)
{
e.Item.Cells[cellIndex].Text = System.Text.Encoding.Default.GetString(buf, 0, 30 - 1) + "...";
}
<FONT face="宋体">
<asp:TextBox id=TextBox5 runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.fcontactname") %>' CssClass="myinput">
</asp:TextBox></FONT>
</ItemTemplate>