Solved

Limit the length of a string using DataTextFormatString

Posted on 2006-11-13
7
1,487 Views
Last Modified: 2008-01-09
Hi,

I am binding a dropdown box to a datareader, I would like to limit the length of the strings because if the string is grater than 25 CHR then it starts to push my formatting on my page around


        Manufacturers.DataSource = ManuReader
        Manufacturers.DataTextField = "SupplierName"
        Manufacturers.DataTextFormatString = HERE IS THE PROBLEM
        Manufacturers.DataBind()

I know I can loop through the datareader and use left(STRING,25)  but I would like to know if I can use DataTextFormatString

Thanks
0
Comment
Question by:bhermer
[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
7 Comments
 
LVL 9

Expert Comment

by:kraffay
ID: 17933844
The easiest way would be to change your SQL to only return the first 25 characters of the field with SUBSTRING function.

DataTextFormatString is for numeric formatting.
0
 
LVL 3

Expert Comment

by:Birdbuster
ID: 17934730
So what should the format do when its longer then 25 characters, that what i dont' understand???

This will code will make it so the dropdown is 25 characters long.
Manufacturer.Width = 25;
0
 
LVL 4

Author Comment

by:bhermer
ID: 17936931
kaffay, What would my SQL look like? currently it is

SELEC DISTINCT SupplierName From Products ORDER By SupplierName ASC


BirdBuster, When over 25 CHr long I would truncate to read  "phillips semi cond..." or similar. I tried setting the width iof the combo box, but it resizes it when you put a 50 CHR string in it and as it is in my Nav bar on the l;eft of my page it pushes all my tables about.

0
Independent Software Vendors: 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 96

Expert Comment

by:Bob Learned
ID: 17937623
What is the database type?  SQL Server?  Access?

Bob
0
 
LVL 4

Author Comment

by:bhermer
ID: 17938270
MySQL
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 17939018
Depending on the version of MySQL, you should be able to do something like this:

SELECT SUBSTRING(Field1, 1, 25) AS Field1

   or

SELECT LEFT(Field1, 25) AS Field1

Bob
0
 
LVL 4

Author Comment

by:bhermer
ID: 17951269
Thanks Bob, that worked great!
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

Suggested Solutions

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

734 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