<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Font-Size="Small" STYLE="border-collapse:separate" BorderWidth="0px" ForeColor="#333333" CellPadding="2" EnableViewState="False" Width="100%" Height="171px">
<HeaderStyle Font-Bold="False" HorizontalAlign="Center" BackColor="#77BFD8" ForeColor="Black" Height="22px"></HeaderStyle>
<Columns>
<asp:BoundField DataField="RowNumber" HeaderText="序号" >
<ControlStyle Width="3%" />
</asp:BoundField>
<asp:BoundField DataField="event_type" HeaderText="事件类型" >
<ControlStyle Width="4%" />
</asp:BoundField>
<asp:BoundField DataField="event_exp" HeaderText="事件说明" />
<asp:BoundField DataField="event_value" HeaderText="事件特征值" />
<asp:BoundField DataField="exception_exp" HeaderText="事件描述" />
<asp:BoundField DataField="event_ip" HeaderText="IP地址" />
<asp:BoundField DataField="lastest_time" HeaderText="操作时间" />
<asp:BoundField DataField="latest_user_name" HeaderText="操作用户" />
<asp:BoundField DataField="latest_dept_name" HeaderText="操作部门" />
<asp:BoundField DataField="role_name" HeaderText="所属角色" />
</Columns>
<AlternatingRowStyle BackColor="#E1F5FB" />
<RowStyle Height="22px" />
</asp:GridView>
请问, 我想让DataField="exception_exp" 这个字段里的内容超过10个字的就直接加上"..."这应该怎么做呢??????
谢谢帮忙!!!!
<HeaderStyle Font-Bold="False" HorizontalAlign="Center" BackColor="#77BFD8" ForeColor="Black" Height="22px"></HeaderStyle>
<Columns>
<asp:BoundField DataField="RowNumber" HeaderText="序号" >
<ControlStyle Width="3%" />
</asp:BoundField>
<asp:BoundField DataField="event_type" HeaderText="事件类型" >
<ControlStyle Width="4%" />
</asp:BoundField>
<asp:BoundField DataField="event_exp" HeaderText="事件说明" />
<asp:BoundField DataField="event_value" HeaderText="事件特征值" />
<asp:BoundField DataField="exception_exp" HeaderText="事件描述" />
<asp:BoundField DataField="event_ip" HeaderText="IP地址" />
<asp:BoundField DataField="lastest_time" HeaderText="操作时间" />
<asp:BoundField DataField="latest_user_name" HeaderText="操作用户" />
<asp:BoundField DataField="latest_dept_name" HeaderText="操作部门" />
<asp:BoundField DataField="role_name" HeaderText="所属角色" />
</Columns>
<AlternatingRowStyle BackColor="#E1F5FB" />
<RowStyle Height="22px" />
</asp:GridView>
请问, 我想让DataField="exception_exp" 这个字段里的内容超过10个字的就直接加上"..."这应该怎么做呢??????
谢谢帮忙!!!!
str = str.Length > 10 ? str + "..." : str;
{
if (b.Length < i)
{
return str;
}
else
{
return str.Substring(0,i) + "...";
}
}
前台可以这样取方法.
你们所说的在一般绑定中是这样的,可是这次这个Gridview 绑定是 直接用<asp:BoundField DataField="RowNumber" HeaderText="序号" >
这样的话前台取这个方法就不行了```
//截取字符串
str是你所要截取的字符串 number 是长度
public string CutString(string str, int number)
{
if (str.Length > number)
{
return str.Substring(0, number) + "...";
}
else
{
return str;
}
}
将你需要转换的那一列转换成模板列 用这种方式调用就可以了
Text='<%# CutString( Eval("Title").ToString(),15)%>' 在页面上这样调用
在里头写如果是数据行,就对e.Row.Cells[4].Text判断长度,长度过多就处理下好了