Geeks With Blogs

News

Microsoft MVP


DZone MVB


Moderator at CodeASP.NET


Quiz Master







free counters
Free counters
Added on January 19,2012


Follow Me @vmsdurano

A bit About Me



Disclaimer
The opinions expressed herein are my own personal opinions and does not represent the opinions of my employers. Nor does it represent the opinion of my dog, because I don’t have one.


Vinz' Blog (ProudMonkey) "Code, Beer and Music ~ my way of being a programmer"

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!

Technorati Tags: ,,
Posted on Friday, September 12, 2008 1:49 AM ASP.NET , Tips&Tricks , GridView | Back to top


Comments on this post: Limiting the Data being displayed in the GridView and Display Tooltip

# re: Limiting the Data being displayed in the GridView and Display Tooltip
Requesting Gravatar...
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.
Left by Ajeesh on Oct 04, 2008 5:19 AM

# re: Limiting the Data being displayed in the GridView and Display Tooltip
Requesting Gravatar...
that was very helpful.... thnx
Left by yogi on May 07, 2009 10:35 PM

# re: Limiting the Data being displayed in the GridView and Display Tooltip
Requesting Gravatar...
Hi,

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

Pls keep them coming.

Thankz
Left by Emmao on Aug 17, 2009 4:03 AM

# re: Limiting the Data being displayed in the GridView and Display Tooltip
Requesting Gravatar...
Hi, I try to apply this code but the e.Row.RowType in my app is Header and I want to modify a cell. Any ideas? thanks
Left by yalvinovino on Jul 27, 2010 6:20 AM

# re: Limiting the Data being displayed in the GridView and Display Tooltip
Requesting Gravatar...
my mistake, sorry, the code works perfectly
Left by yalvinovino on Jul 28, 2010 6:58 AM

# re: Limiting the Data being displayed in the GridView and Display Tooltip
Requesting Gravatar...
Hi,Thanks for your info
Left by siva on Dec 30, 2010 3:22 PM

# re: Limiting the Data being displayed in the GridView and Display Tooltip
Requesting Gravatar...
Thank you.
Left by Abhishek on Mar 28, 2011 6:08 PM

# re: Limiting the Data being displayed in the GridView and Display Tooltip
Requesting Gravatar...
Hi,
it is working fine..

please let me know how to display the long data i.e 500 characters length in tool tip.

the given solution is displaying some part of data in it i.e max 150 characters out of 500

Please help me

ThanQ
Left by Ramesh Mukkala on Jul 07, 2011 2:51 PM

# re: Limiting the Data being displayed in the GridView and Display Tooltip
Requesting Gravatar...
Dear,

your solution is fantastic, you just need to add one more line:

Then add following in Gridview in .aspx file

OnRowDataBound="GridView1_RowDataBound":

<asp:GridView ID="GridView1" runat="server"
GridLines="None" AllowPaging="True" AutoGenerateDeleteButton="True"
AutoGenerateEditButton="True" DataSourceID="DS" PageSize="1"
OnRowDataBound="GridView1_RowDataBound">
Left by Himanshu Verma on Nov 05, 2012 5:52 PM

comments powered by Disqus

Copyright © Vincent Maverick Durano | Powered by: GeeksWithBlogs.net