The following snippet below describes on how we are going to limit the Text displayed in the boundfield column of the GridView and display the original data in the ToolTip when user hovers the mouse for a particular cell.
C#
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
ViewState["OrigData"] = e.Row.Cells[0].Text;
if (e.Row.Cells[0].Text.Length >= 30) //Just change the value of 30 based on your requirements
{
e.Row.Cells[0].Text = e.Row.Cells[0].Text.Substring(0, 30) + "...";
e.Row.Cells[0].ToolTip = ViewState["OrigData"].ToString();
}
}
}
VB.NET
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
ViewState("OrigData") = e.Row.Cells(0).Text
If e.Row.Cells(0).Text.Length >= 30 Then 'Just change the value of 30 based on your requirements
e.Row.Cells(0).Text = e.Row.Cells(0).Text.Substring(0, 30) + "..."
e.Row.Cells(0).ToolTip = ViewState("OrigData").ToString()
End If
End If
End Sub
That simple! Hope this Helps!