ロック済み Get combo valuemember in datarepeater?

  • Monday, June 15, 2009 7:59 PM
     
     
    I'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
    •  

All Replies

  • Monday, June 15, 2009 10:53 PM
    Moderator
     
     
    Hi 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
     
      Has Code

    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 PM
     
     
    Nobody 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 PM
    Moderator
     
     
    Hi 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 .  

    http://social.msdn.microsoft.com/Forums/en-US/vbpowerpacks/thread/15e6d858-db68-4eaa-8ed3-670927c66ec4

    John

  • Wednesday, July 08, 2009 7:09 PM
     
     
    Let me review my coding and how I have the combo set up.  Thanks for your help.