Solved

Help formating the text in a LinkButton

Posted on 2008-09-29
7
335 Views
Last Modified: 2013-12-17
In Code Behind, I must concatenate two different texts in a linkButton that resides in a GridView (<ItemTemplate>)

The trick is that the I need a newspaper-column effect. For example
First column can have up to 6 chars
Second column is a number that can have up to 5 digits

ABC          234
Z               1
ABCDEF  54321
DR           3434

My problem is that 2, 3, 4 or 5 spaces are represented as only ONE space in the GridView in runtime. Thus, the results display as
ABC 234
Z 1
ABCDEF  54321
DR 3434

I wanted to display these values in two different columns and let the browser align these column automaticaly, but per my architect demands, we need to concatenate them as one column.

Thanks for your help.
0
Comment
Question by:rpatronee
[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
  • 3
7 Comments
 
LVL 20

Expert Comment

by:informaniac
ID: 22602905
In the rowdatabound event of the grid do this...

LinkButton lnk = (LinkButton) e.Row.FindControl("lnk1");
lnk.Text = e.row.cells[0].Text.Trim() + " " + e.row.cells[1].Text.Trim()
0
 

Author Comment

by:rpatronee
ID: 22605131
Informania,

I think the basic problem boils down to the spaces not been treated as monospace. I could have:
ABC    383     (three spaces in between)
A         12       (five spaces in between)

But, it displays as:
ABC 383
A 12

In other words, the spaces are not being used to align the two values contained in the same column.
I tried to use  font-family: Times New Roman, Monospace; in my style sheet, but the spaces are still not treated as monospace.

Thanks !





0
 
LVL 1

Expert Comment

by:tcss
ID: 22605937
Is it possible to substitue tabs "\t" to alighn the text ie x specaes = 1 tab
0
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!

 
LVL 20

Expert Comment

by:informaniac
ID: 22611672
How are u fetching the two columns

ABC and 123

Are they separate columns?
0
 

Author Comment

by:rpatronee
ID: 22617506
Informaniac,

These are two different columns from the database. I need to combined them onto one column in the griedview, making sure I pad enough spaces in between these two values, so that the browser aligns them.  

The problem is that the browser does not align the two "artificial" columns correctly.  I believe there is a way to tell the browser to display each character, including spaces, using the same width for all.

I have tried using the following CSS, but it still does not work.

font-size: 10px;
font-family: Courier, Monospace ;

Any ideas?



0
 
LVL 20

Accepted Solution

by:
informaniac earned 225 total points
ID: 22631712
In the d/b query that u write

try writing like this

select replace(col1+col2,' ','&nbsp;') as link and bind this column to the gridview...

U need to replace space with &nbsp; for the grid to display a space
0
 

Author Closing Comment

by:rpatronee
ID: 31501367
Yup !    I just made sure I was using a monospace font, such as New Courier.

Thanks!
0

Featured Post

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

Suggested Solutions

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

740 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