Solved

BoundField trim text gridview

Posted on 2012-03-27
3
1,184 Views
Last Modified: 2012-04-12
how can we do this ?
0
Comment
Question by:goodluck11
3 Comments
 
LVL 20

Expert Comment

by:BuggyCoder
Comment Utility
Two ways to do this:-
1. use ondatabound event, find the control and trim its text using trim method of string instance.
2. convert your bound field to TemplateField and do something like this:-

<asp:TemplateField HeaderText="Bulletin" >
<ItemTemplate>
<asp:Label ID="LabelBulletin" runat="server" Text='<%# Eval("Bulletin").ToString().Substring(0,Math.Min(20,Eval("Bulletin").ToString().Length))+"...." %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>

Open in new window

0
 
LVL 53

Expert Comment

by:Dhaest
Comment Utility
For trimming values in gridview follow this code-


private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            if (e.RowIndex > -1)
           {
                if (e.Value != null)
               {
                   e.Value = e.Value.ToString().Trim();
                }
           }  
      }
0
 
LVL 16

Accepted Solution

by:
Rose Babu earned 500 total points
Comment Utility
update the cell data using RowDataBound event as like below.
protected void GridView1_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
{

	if (e.Row.RowType == DataControlRowType.DataRow) {

		for (i = 0; i <= e.Row.Cells.Count - 1; i++) {
			e.Row.Cells[i].Text = e.Row.Cells[i].Text.Trim();

		}

	}

}

Open in new window

Try this. It will work for you.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now