Vinz' Blog

"Code, Beer and Music" ~ my way of being a programmer!
posts - 123, comments - 343, trackbacks - 0

My Links

News

Archives

Image Galleries

Limiting the Data being displayed in the GridView and Display Tooltip

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 it Helps!

Print | posted on Friday, September 12, 2008 1:49 AM |

Feedback

Gravatar

# re: Limiting the Data being displayed in the GridView and Display Tooltip

hey thanx.. that was a great help. i was looking at javascript options 4 this... it hadnt occured to me that we can get ToolTip for e.Row.Cells(0) also...

cheers.
10/4/2008 5:19 AM | Ajeesh
Gravatar

# re: Limiting the Data being displayed in the GridView and Display Tooltip

that was very helpful.... thnx
5/7/2009 10:35 PM | yogi
Gravatar

# re: Limiting the Data being displayed in the GridView and Display Tooltip

Hi,

Another cool stuff; about the coolest I have gotten from you.

Pls keep them coming.

Thankz
8/17/2009 4:03 AM | Emmao
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 
 

Powered by: