• gridview自动换行


    首先是GridView 中的文本不自动换行,隐藏超出宽度部分,可以使用以下函数:
    return (str.Length > num) ? str.Substring(0, num) + "..." : str;
    int num 是你要截取的字符串的长度,然后把这个函数写在行绑定数据的事件中即可。
    要是要使GridView里的内容自动换行的话,使用以下办法
    在页面加入属性:style =" word-break :break-all ; word-wrap:break-word " (table或div 等的属性里)
    或设置
    <asp:TemplateField>
                <itemtemplate>                       
            <asp:LinkButton ID="linkbNewsTitle" runat="server" Text='<%# Bind("ch_Remark") %>' ToolTip='<%# Bind("ch_Remark") %>'>                      
            </asp:LinkButton>                            
            </itemtemplate>
                <itemstyle width="300" />
            </asp:TemplateField>
          protected void GridView1_DataRowBound(object o, GridViewRowEventArgs e)
            {
                if (e.Row.RowType == DataControlRowType.DataRow)
                { //设置要换行的模板列 
                    e.Row.Cells[0].Attributes.Add("style", "word-break :break-all ; word-wrap:break-word"); e.Row.Cells[1].Attributes.Add("style", "word-break :break-all ; word-wrap:break-word");
                }
            }
            //或者 如何实现:GridView 控件中显示的文本不自动换行,隐藏超出宽度部分     
            protected void gvNewsManage_RowDataBound(object sender, GridViewRowEventArgs e)
            {
                if ((LinkButton)e.Row.FindControl("linkbNewsTitle") != null)
                {
                    LinkButton linkbTitle = (LinkButton)e.Row.FindControl("linkbNewsTitle"); if (linkbTitle.Text.Length > 10)
                    {
                        linkbTitle.Text = linkbTitle.Text.Substring(0, 9) + "";
                    } Label lblinknewID = (Label)e.Row.FindControl("ltgvnid");
    
                    linkbTitle.PostBackUrl = "EditNewsContent.aspx?ID=" + lblinknewID.Text;
                }
            }
            protected void gvNewsManage_RowDataBound(object sender, GridViewRowEventArgs e)
            {
                string strValue = e.Row.Cells[18].Text.ToString();
                if (strValue != null)
                {
                    if (strValue.Length > 9)
                    {
                        e.Row.Cells[18].Text = strValue.Substring(0, 9) + "";
                    }
                }
            }
  • 相关阅读:
    转载:从git仓库中删除不必要的文件
    问题:Swiper父容器隐藏时实例化组件,组件滑动失效
    图片预加载
    移动端苹果手机:图片没有加载完成前,白色边框线是怎么来的
    bower 安装依赖提示 EINVRES Request to https://bower.herokuapp.com/packages/xxx failed with 502
    H5序列帧播放
    盟军敢死队
    二维游戏开发的点滴
    用c语言开发游戏 快乐的痛 笑着哭
    ibatis
  • 原文地址:https://www.cnblogs.com/bingle/p/2494208.html
Copyright © 2020-2023  润新知