Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Limit the length of a string using DataTextFormatString

Posted on 2006-11-13
7
Medium Priority
?
1,513 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
Industry Leaders: 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 2000 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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

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…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

636 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