Monday, June 15, 2009 7:59 PMI've got a combobox in a datarepeater control and I'm trying to get the valuemember of the selected item to store back to the database. So far I'm only able to obtain the displaymember, not the valuemember. Am I doing something wrong? Here's my code:
objCommand.Parameters.Add("@PeopleTypeID", SqlDbType.VarChar, 50).Value = _ PeopleTypesDatarepeater.CurrentItem.Controls("cboPeopleType").Text.Trim.ToString
When I set a breakpoint on this line, and view the value of ..CurrentItem.Controls.., it displays the displaymember. I want the valuemember which is an integer identity column. I understand that the ...Text.Trim.ToString expects a text value but I'm not sure what to put here.
Any help or advice is appreciated. Thanks.
- Edited by kris_hood Monday, June 15, 2009 8:00 PM reformat coding block
Monday, June 15, 2009 10:53 PMModeratorHi Kris,
To get the ValueMember from a ComboBox, I believe you need to get the SelectedValue, not the Text.
Steve Hoag Microsoft aka the V-Bee
Tuesday, June 16, 2009 1:55 PM
The problem I'm having though is that if I try to get the SelectedValue, it's always zero. The combo appears to be working just fine. I can select any item I want. I just can't capture the SelectedValue. Here is my code in the SelectedItemChanged event for the combo:
Private Sub cboPeopleType_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboPeopleType.SelectedIndexChanged intValue = cboPeopleType.SelectedValue End Sub
I changed the coding from my initial posting to this:
objCommand.Parameters.Add("@PeopleTypeID", SqlDbType.Int, 4).Value = intValue
I figured there was some special syntax I had to do because the combo is in a datarepeater control.
Thanks for your help.
Monday, June 22, 2009 1:21 PMNobody has had this problem other than me? Normally getting the SelectedValue is no problem but I can't seem to obtain it with this datarepeater control.
Friday, July 03, 2009 3:31 PMModeratorHi Kris,
Combox in the DataRepeater should behavior same as used in other place.
I guess the issue may more related how you defined your ComboBox.
Link to your related post .
Wednesday, July 08, 2009 7:09 PMLet me review my coding and how I have the combo set up. Thanks for your help.