?
Solved

BoundField trim text gridview

Posted on 2012-03-27
3
Medium Priority
?
1,273 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 2000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

762 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