Solved

Limit the length of a string using DataTextFormatString

Posted on 2006-11-13
7
1,491 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
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 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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

717 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