?
Solved

combobox selected value in database

Posted on 2008-06-26
5
Medium Priority
?
2,933 Views
Last Modified: 2013-11-07
I have a combobox in an application which is in wpf and linq
 <ComboBox Height="23" HorizontalAlignment="Left" Margin="70,32.24,0,0" Name="cbGroup" VerticalAlignment="Top" Width="187" AllowDrop="True" SelectedIndex="0">
                            <ComboBoxItem>Adult</ComboBoxItem>
                            <ComboBoxItem>Youth</ComboBoxItem>
                            <ComboBoxItem>Children</ComboBoxItem>
                            <ComboBoxItem>Unknown</ComboBoxItem>
                        </ComboBox>

I am using the following code to insert the selected value in the database

 NewContact.AgeGroup = (string)this.cbGroup.SelectedValue.ToString();

but this  inserts in the database
System.Windows.Controls.ComboBoxItem: Children
please let me know how  i can insert the text value of the selected value in the database
0
Comment
Question by:shoopak
3 Comments
 
LVL 16

Expert Comment

by:burakiewicz
ID: 21875905
try this
NewContact.AgeGroup = this.cbGroup.SelectedItem.Value.ToString();
0
 

Author Comment

by:shoopak
ID: 21877817
this doesn't work because

SelectedItem doesn't have a value property

This application is in wpf  and dot net 3.5


app.gif
0
 
LVL 11

Accepted Solution

by:
Mihai Stancescu earned 200 total points
ID: 21907998
Try this
NewContact.AgeGroup = this.cbGroup.Text;



Hope this helps!

Regards,
Mishu
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Loops Section Overview
Suggested Courses
Course of the Month17 days, 11 hours left to enroll

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question