Home > Uncategorized > Long Texts And GridViews: What A Tooltip

Long Texts And GridViews: What A Tooltip

Yet another GridView tweak. Ever tried to display a big chunk of text into a GridView and saw your entire page ultimately ruined? Fear no more. There’s a very, very simple solution and that is using a Tooltip. It’s easy to do, just follow these steps:

1Cut a hole in a box: First, we need to create a RowDataBound event for our GridView. You can find this from GridView properties -> Events -> Data-> RowDataBound

In your .aspx page it should look something like this:


2- You put your junk in that box: in the code behind, populate RowDataBound

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
            if (e.Row.RowType == DataControlRowType.DataRow)
                ViewState["myToolTip"] = e.Row.Cells[0].Text;
                if (e.Row.Cells[0].Text.Length >= 30)
                    e.Row.Cells[0].Text = e.Row.Cells[0].Text.Substring(0, 30) + "...";
                    e.Row.Cells[0].ToolTip = ViewState["myToolTip"].ToString();


3- Make her open the box: now if you just hover your mouse over the row containing … a tooltip will appear with the complete string in it.

And that’s the way you do it!

Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: