Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

Hi,

 

I don't know why but the text formatting doesn't work at all for the dropdownlist. The reader return whole integers and I want to add two quotes to simulate inches. 20 -> 20''

 

I tired putting it outside the loop, and inline (html), same results.

If dr.HasRows() Then

drpWidth.Items.Add(New ListItem("",""))

While dr.Read()

drpWidth.Items.Add(New ListItem(dr.GetInt32(0),dr.GetInt32(0)))

drpWidth.DataTextFormatString = "{0:C}"

End While

Else
drpWidth.Items.Add(New ListItem("No Data",""))
End If

 

Thanks

 

* Um why aren't the code tags working? :/ The code is between them.

Edited by PlausiblyDamp
Posted

Well {0:C} is currency

 

Try:

 

DataTextFormatString = '{0}"'

 

Also you would set this property for the data list only once before the loop (after the if), not during - this is causing you to reset the DataTextFormatString for drpWidth over and over again to the same thing - it will be reset X amount of times where X is the amount rows in your reader and throughout the whole thing the value will never change so you're just wasting processor.

Posted

I know thats 0:C is for currency I tested '{0}"' also.

Regardless of the format I put the text is the same.

 

If dr.HasRows() Then
drpWidth.DataTextFormatString = "{0}''" 
drpWidth.Items.Add(New ListItem("",""))
While dr.Read()
 drpWidth.Items.Add(New ListItem(dr.GetInt32(0),dr.GetInt32(0)))
End While
Else
drpWidth.Items.Add(New ListItem("No Data",""))
End If

  • Administrators
Posted (edited)

Fixed the code block - it didn't seem to like the mixture of code and left blocks for some reason.

Also switched to the vb tags to get syntax colouring.

 

As to the problem itself, IIRC the DataTextFormatString property only applies when databinding, in your case as you are adding the entries manually it will not be applied; either add the strings already formatted or bind to the data reader.

Edited by PlausiblyDamp

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...