I have an aspx page that has a listview. Within the listview I have a column named BADGEID. When inserting the BADGEID as a textbox with the below code, everything works properly:

<asp:TextBox ID="BADGE" runat="server" Text='<%# Bind("BadgeID") %>'

I need this to be a DropDownList and I changed the textbox above to the below:

<asp:DropDownList ID="BADGE" runat="server" DataSourceID="SqlDataSource2" DataTextField="BADGE" DataValueField="BADGE" />

The listbox contains the items I need but when I send the information, the item selected in the DropDownList is not sent to the database.

Please let me know what I am missing or doing wrong. This is the first aspx with a DropDownList I have ever created.

7 Years
Discussion Span
Last Post by vgulavni

To save values selected from a DropDownList, you must use SelectedItem. This is how you use it:-

string insertCommand="insert into TableName values ('"+BADGE.SelectedItem.Text.ToString()+"')";

SqlCommand commandObject=new SqlCommand(insertCommand, connectionObject);


Don't worry, we are all learners.

Edited by pinkygirl: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.