Solved

Limit the length of a string using DataTextFormatString

Posted on 2006-11-13
7
1,481 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
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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying 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 have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
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…

861 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