zoukankan      html  css  js  c++  java
  • 控制GridView中字段的长度,规范数据

    前台:

           <asp:GridView ID="GridView1" runat="server" OnRowDataBound="GridView1_RowDataBound">
                <Columns>
                    <asp:TemplateField>
                        <HeaderTemplate>
                            <input id="cb_head" type="checkbox" name="cb_head" onclick="SelectAll(this,<%=GridView1.ClientID %>);" />
                        </HeaderTemplate>
                        <ItemTemplate>
                            <asp:CheckBox ID="ChkChild1" runat="server" />
                        </ItemTemplate>
                        <ItemStyle HorizontalAlign="Center" />
                        <FooterStyle HorizontalAlign="Center" />
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>

    后台:

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            //在RowDataBound事件中调下面的方法
            int[] cellIndexs = new int[4];
    
            this.setGridViewInfo(e,1, cellIndexs, 11);
        }
    
        #region
        /// <summary>
        /// 控制GridView中显示字符串的长度 并 在ToolTip中显示全部文本
        /// </summary>
        /// <param name="e">GridViewRowEventArgs e</param>
        /// <param name="cellIndexs">GridView中显示单元格的个数</param>
        /// <param name="maxStrLength">要显示的最大字符串长度</param>
        private void setGridViewInfo(System.Web.UI.WebControls.GridViewRowEventArgs e,int stata_index, int[] cellIndexs, int maxStrLength)
        {
            string CellText = string.Empty;
    
            //因为我的GridView前一列是CheckBox,所以i从1开始
            for (int i = stata_index; i < cellIndexs.Length; i++)
            {
                CellText = e.Row.Cells[i].Text.Trim();
    
                if (CellText.Length > maxStrLength)
                {
                    e.Row.Cells[i].Text = CellText.Substring(0, maxStrLength - 1) + " <strong style='Color:blue' mce_style='Color:blue'> ... </strong>";
    
                    e.Row.Cells[i].ToolTip = CellText;
                }
            }
        }
        #endregion
  • 相关阅读:
    php foreach的使用注意
    php数组遍历 使用foreach
    PHP strip_tags() 函数
    php nl2br() 函数
    php文件上传
    一个网站雏形
    jsp接收相同复合参数 request.getParameterValues()用法
    使用div+css制作简单导航 以及要注意问题
    Java 类与对象
    java 基础
  • 原文地址:https://www.cnblogs.com/houlin/p/3790946.html
Copyright © 2011-2022 走看看