[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

BoundField trim text gridview

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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

650 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