在VS2005中,如何在把每列的宽度固定下之后,让GridView不换行,即只显示部分数据。

解决方案 »

  1.   

    <body style=word-break:break-all>
      

  2.   

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
            {
                if (e.Row.RowType==DataControlRowType.DataRow)
                {
                    if (e.Row.Cells[1].Text.Length>10)
                    {
                        e.Row.Cells[1].Text = e.Row.Cells[1].Text.Substring(0, 10) + "...";
                    }
    }
    }
      

  3.   

    这个需要在相应的事件中截取字符串了。
    贴点代码供参考:
    protected void gdvLog_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)//判定当前的行是否属于datarow类型的行
            {
              
                Label lblUserAgent = (Label)e.Row.FindControl("lblUserAgent");
                lblUserAgent.Text = lblUserAgent.ToolTip.Substring(0, 45);
                
    在ASPX页面中模板列加入这个lbluserAgent控件
    <ItemTemplate>
                                            <asp:Label ID="lblUserAgent" runat="server" EnableViewState="False" ToolTip='<%# Eval("userInfo") %>'></asp:Label>
                                            </ItemTemplate>
      

  4.   

    在GridView1_RowDataBound事件里面:
    private void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
            {
                if (e.Row.RowType!=DataControlRowType.DataRow)
                {
                    if (e.Row.Cells[1].Text.Length>10)
                    {
                        e.Row.Cells[1].Text = e.Row.Cells[1].Text.Substring(0, 10) + "";
                    }
    }
    }