aspdotnet-suresh offers articles and tutorials,csharp dot net, articles and tutorials,VB.NET Articles,Gridview articles,code examples of 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

how to show limited characters in gridview columns using and how to show the tooltip for gridview rows and cells or how to show limit characters in gridview column using

Dec 10, 2010

In this article I will explain how to show limited characters in gridview using


I have created one application for that we have prepared one feedback form to collect feedback from users regarding our application for that we have taken gridview to bind all the feedbacks into one page. Here some of the users have given one line of feedback some of the users have given two lines of feedback remaining people have given feedback with bigger matter at that time if we bind all the feedbacks to one gridview at that time gridview size has increased a lot and in some rows matter is small but columns size is bigger that is just like this
For that reason we tried to maintain consistency for entire gridview to maintain consistency for gridview we need to write functionality in Gridview RowDataBound event
Design your aspx page like this

<html xmlns="">
<head runat="server">
<title>Gridview With Limited Characters</title>
<form id="form1" runat="server">
<table   cellpadding="0" cellspacing="0" width="300px" align="center">
<asp:GridView ID="GridView1" runat="server" Width="100%" 
CssClass="feedbacklink" AutoGenerateSelectButton="True"  
onrowdatabound="GridView1_RowDataBound" PageSize="5" >
<asp:TextBox ID="txtmsg" runat="server" TextMode="MultiLine"
CssClass="textarea" Width="300px" ></asp:TextBox></td>

In code behind write this functionality to bind gridview and write functionality in Gridview_Rowdatabound to limit the characters in gridview columns.

string strConn = "Data Source=MYSystem;Initial Catalog=MySamplesDB;Integrated Security=True";
protected void Page_Load(object sender, EventArgs e)
if (!IsPostBack)

public void bindGrid()
SqlConnection con = new SqlConnection(strConn);
DataSet myDataSet = new DataSet();
SqlCommand cmd = new SqlCommand("Select * from Feedback", con);
// cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter myDataAdapter = new SqlDataAdapter(cmd);
GridView1.DataSource = myDataSet;
// GridView1.Columns[3].Visible = false;
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
int i = 0;
e.Row.Cells[3].Visible = false;
if (e.Row.RowType == DataControlRowType.DataRow)
foreach (TableCell cell in e.Row.Cells)
string s = cell.Text;
if (cell.Text.Length > 25 && (i == 3))
cell.Text = cell.Text.Substring(0, 25) + "....";
cell.ToolTip = s;

After writing this functionality gridview looks like this


If you enjoyed this post, please support the blog below. It's FREE!

Get the latest,, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email


Naresh said...

I'm getting error as
e.Row.Cells[3].Visible = false; ====> Error:Specified argument was out of range of valid vavalues parameter:Index

Anonymous said...


Works fine!!!!


Anonymous said...

Work like a charm!!!


Y said...

but when Export to excel required then what to do?
It Export with "......" not whole data

Unknown said...

what is "!IsPostBack"

Anonymous said...

I have followed all your code, and in my database, I added the 3rd column is id, so when my code has changed the cell [2] cell [3] but did not show up "...."as in code which instead show all the data in the column description into one long line. In my database is: id, subject, description.Please help me!!!!

Unknown said...

Nat chaal tu.....................

Unknown said...


Anonymous said...

what i have to do if have i designed gridview in my own that means inside 1 row i spllited into many table???? plz help me out

Anonymous said...

i getting this error

e.Row.Cells[3].Visible = false; => Error:Specified argument was out of range of valid vavalues parameter:Index

Christo said...


This is fine, but the issue is, if i want to export the gridview to Excel, than '.....' is showing instead of full statement. so, please tell the alternate way to export report to excel

Anonymous said...

thank u ..suresh...u r amazing

Sam said...

Thanks This Helped a Lot !!

Anonymous said...

Thanks a lott.

Unknown said...

nice are too good..

Sakshi said...

Thanks for sharing with us...

Inzynier Umair said...

How to use this substring method for ajaxhtmlextender content. i.e the data which is stored in database having html tags so while using subtring method it shows the data with html tags so can you please tell me the alternative solution of substring for ajaxhtmExtender content. and im not displaying it in gridview im simply using div tag with run=server in c#

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.