解決GridView中字段過長問題

 GridView中字段過長可以在RowDataBound事件中對此字段進行截取,然後在ToolTip 屬性中顯示全部內容。

例:

    /// <summary>
    /// 行綁定
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void gridBulletinInfo_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            string strId = ((HiddenField)e.Row.Cells[1].FindControl("hiddID")).Value;
            if (strId == "" || strId == "0" || strId == "&nbsp;")
            {
                ((Label)e.Row.Cells[2].FindControl("Label1")).Text = "";
                return;
            }

            LinkButton linkbtn = e.Row.Cells[1].FindControl("LinkButton3") as LinkButton;
            string str1 = linkbtn.Text;
            linkbtn.ToolTip = str1;
            if (str1.Length > 26)
            {
                str1 = str1.Substring(0, 25) + "...";
            }
            linkbtn.Text = str1;
        }
    }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章