[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1525
  • Last Modified:

Limit the length of a string using DataTextFormatString

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
bhermer
Asked:
bhermer
1 Solution
 
kraffayCommented:
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
 
BirdbusterCommented:
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
 
bhermerAuthor Commented:
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
Bob LearnedCommented:
What is the database type?  SQL Server?  Access?

Bob
0
 
bhermerAuthor Commented:
MySQL
0
 
Bob LearnedCommented:
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
 
bhermerAuthor Commented:
Thanks Bob, that worked great!
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now