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 == " ")
{
((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;
}
}