Solved

BoundField trim text gridview

Posted on 2012-03-27
3
1,247 Views
Last Modified: 2012-04-12
how can we do this ?
0
Comment
Question by:goodluck11
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 20

Expert Comment

by:BuggyCoder
ID: 37770157
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
ID: 37770159
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
ID: 37771278
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

726 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