Polar Bear Posted September 28, 2005 Posted September 28, 2005 (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 September 29, 2005 by PlausiblyDamp Quote
bri189a Posted September 29, 2005 Posted September 29, 2005 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. Quote
Polar Bear Posted September 29, 2005 Author Posted September 29, 2005 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 Quote
Administrators PlausiblyDamp Posted September 29, 2005 Administrators Posted September 29, 2005 (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 September 29, 2005 by PlausiblyDamp Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.