datagrid某一行中的某个单元格撑大撑高问题 <%# DataBinder.Eval(Container.DataItem,"字段").ToString().Substring(0,15)+"……"%> 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你可以自己限定显示多少个字符,如果多余限定字符就已……显示: private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { string strID = ""; if (e.Item.ItemType == ListItemType.Item ||e.Item.ItemType ==ListItemType.AlternatingItem) { if (e.Item.Cells[1].Text.Length >26) { e.Item.Cells[1].Attributes.Add("内容",e.Item.Cells[1].Text); e.Item.Cells[1].Text = e.Item.Cells[1].Text.Substring(0,26)+"…………"; } } }e.Item.Cells[1]改成你要限制的那一列 在itembound事件中加入下列代码:if(e.item.ItemType != ItemTypeList.Header && e.item.ItemType != ItemTypeList.booter){for(int i = 0 ; i < e.item.Cells.Count;i++){string strText = e.item.Cells[i].Text;if (strText.Length >20){ e.item.Cells[i].Text = strText.SubString(0,17)+'...';}}} 这样写是否简单?<%#DataBinder.Eval(Container.DataItem, "yourKeyField").ToString().Length > 20?DataBinder.Eval(Container.DataItem, "yourKeyField").ToString().Substring(0,20)+"...":DataBinder.Eval(Container.DataItem, "yourKeyField")%> 以上的答案都不能解决DataGrid的宽度按百分比自动适应浏览器的宽度这种情况,因为列宽不固定,要在用户用鼠标调整DataGrid宽度的时候算出每列能容纳多少字符还比较麻烦 asp.net vs2008 dropdownlist控件的问题 图像缩放的问题(只能在高度方向缩放)? PhenMenu 标题问题 CheckBoxList问题 asp.net C#的问题 这句话是什么意思? 怎么去除ViewState信息 现在搜索功能报废了,搜出来的页面全是“无法找到该页”,这些页都丢了吗?csdn的效率真差! 为什么控件不能显示。 再次请教高手!~~~~~~~~~~~~ 高分求救! 如何在asp.net里调用拥有两个个输入参数一个输出参数的存储过程啊?急!!!在线等待
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
string strID = "";
if (e.Item.ItemType == ListItemType.Item ||e.Item.ItemType ==ListItemType.AlternatingItem)
{
if (e.Item.Cells[1].Text.Length >26)
{
e.Item.Cells[1].Attributes.Add("内容",e.Item.Cells[1].Text);
e.Item.Cells[1].Text = e.Item.Cells[1].Text.Substring(0,26)+"…………";
}
}
}
e.Item.Cells[1]改成你要限制的那一列
if(e.item.ItemType != ItemTypeList.Header && e.item.ItemType != ItemTypeList.booter)
{
for(int i = 0 ; i < e.item.Cells.Count;i++)
{
string strText = e.item.Cells[i].Text;
if (strText.Length >20)
{
e.item.Cells[i].Text = strText.SubString(0,17)+'...';
}
}
}
<%#DataBinder.Eval(Container.DataItem, "yourKeyField").ToString().Length > 20?DataBinder.Eval(Container.DataItem, "yourKeyField").ToString().Substring(0,20)+"...":DataBinder.Eval(Container.DataItem, "yourKeyField")%>