Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datagrid column format (only 10 leftmost characters) 1

Status
Not open for further replies.

peekay

Programmer
Oct 11, 1999
324
ZA
I have a databound datagrid and wish to show only the leftmost 10 characters of a certain string field in a certain column. How would I do that ?
Thanks

PK Odendaal
 
After you have done the DataBound(), you can loop through and replace the values of column X with the respective truncated values.
 
i usually would change the sql statement...

SELECT tblID, Substring(tblText,1,10) AS halfString FROM tblStuff

That way, if you have Columns autogenerated, it would only load the 10 characters. Change the halfString to something more user friendly - AS 'My Field'

if you specify the columns, do HeaderText="My Field" DataField="halfString
 
JohnnyBGoode - I could not get your proposal to work.
adamroof - I had thought of your proposal before I posted the question, but could not get it right. However after I read your post and done some fiddling in which I substituted your substring() with mid() I got it to work correctly. Have a star.
This is a very interesting problem many people would have. Ultimately I settled for the solution that fetched the whole field and turned item wrapping off.
Thanks guys.

PK Odendaal
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top