<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个字的就直接加上"..."这应该怎么做呢??????
谢谢帮忙!!!!

解决方案 »

  1.   

    string str = "exception_exp";
    str = str.Length > 10 ? str + "..." : str;
      

  2.   

    自己写个方法,传入字符串,然后调用! public string ChangeByte(string str, int i)
        {
            if (b.Length < i)       
            {
                return str;
            }
            else
            {
                return str.Substring(0,i) + "...";
            }
        }
      

  3.   

    <%# Eval("proname").ToString().Length > 10 ? Eval("proname").ToString().Substring(0, 8) + "…" : Eval("proname")%>
      

  4.   

    <%#ChangeByte(Eval("GDSName").ToString(),20) %>
    前台可以这样取方法.
      

  5.   

    http://blog.csdn.net/zlj002/archive/2011/04/14/6322971.aspx
      

  6.   


    你们所说的在一般绑定中是这样的,可是这次这个Gridview 绑定是  直接用<asp:BoundField DataField="RowNumber" HeaderText="序号" >
    这样的话前台取这个方法就不行了```
      

  7.   

     自己在cs写个方法
    //截取字符串
      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)%>'  在页面上这样调用
      

  8.   

    <%# Eval("proname").ToString().Length > 10 ? Eval("proname").ToString().Substring(0, 8) + "…" : Eval("proname")%>用这个方法也可以,不过用之前你得有个这样的操作转换成模板列,就下面那点蓝色的字体,然后就可以绑定了,楼主试试。
      

  9.   

    得先选中字段,然后转换成templeteFiled,就ok的
      

  10.   

    GridView应该有个Row_Create事件吧
    在里头写如果是数据行,就对e.Row.Cells[4].Text判断长度,长度过多就处理下好了