Jerry,
Depending on which database you use, you can get rid of the spaces by changing the column's data type to a variable-length string in the database. If this is not possible, you can add an expression column to the datatable that takes it's value from ud_value.Trim and use it as the DataValueField instead of ud_value.
>Keith, thanks for the reply.
>
>What can I do then to get rid of the spaces on the drop down list? I create this list by querying a table to get a subset of records. I then use the following to bind the dataset to the drop down list:
>
>
>this.ComboCodes.DataSource = ds.Tables["udc"];
>this.ComboCodes.DataTextField = "ud_desc"; //Friendly name
>this.ComboCodes.DataValueField = "ud_value"; //Actual codes to use.
>this.ComboCodes.SelectedValue = "SomeValue" //Does not work because of spaces in data in dataset.
>this.ComboCodes.DataBind();
>
>
>How can I drop the trailing spaces in the dataset before binding the column to the DataValueField?
>
>Thanks,
>
>Jerry
>
>
>
>>>Using VS2005, I am creating a Asp.Net Webform. This form has a dropdown list webcontrol. I want to populate the dropdown with data from a table and set it's SelectedValue property. All of this works except for the SelectedValue.
>>>
>>>When I look at the HTML source in IE, I notice that the Value tag for the dropdown has trailing spaces next to the value. For Example:
>>>
>>>
>>><option value="0006 ">Description for 0006</option>
>>><option value="0007 ">Description for 0007</option>
>>>
>>>
>>>How do I remove these trailing spaces behind the 0006 and 0007? The only way I can set a SelectedValue for this dropdown is to include the trailing spaces. I prefer not to do this. Below shows two examples, one works the other doesn't. How can I get example one to work?
>>>
>>>
>>>//Example one
>>>this.cbo_soplant.SelectedValue = "0006"; //Does not work.
>>>//Example two
>>>this.cbo_soplant.SelectedValue = "0006 "; //Works.
>>>
>>>
>>>Thanks,
>>>
>>>Jerry
>>
>>Jerry,
>>
>>A DropDownList will only accept a SelectedValue that exactly matches an item in the DataSource.DataValueField. In this case, the datasource is returning padded data.