Drop Down List Selected Index!!!

A

Anthony Judd

When I user click a link buttton i am calling a stored procedure and
provided the required parameters.
Unfortunately it seeems I can't seem to get the right selectedItem when the
page posts.
Any insight into getting around this is appreciated!!!

void new_menu_Click(object sender, EventArgs e) {
String dsn = "Initial Catalog=cms;Data Source=localhost;Integrated
Security=SSPI";
SqlConnection MyConnection = new SqlConnection(dsn);
MyConnection.Open();
SqlCommand cmd = new SqlCommand("add_menu",MyConnection);

cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@menu_name", SqlDbType.VarChar, 40).Value =
menu_name.Text;
cmd.Parameters.Add("@menu_parent", SqlDbType.Int, 4).Value =
menu_parent.SelectedItem.Value;
//always evaluates to first element despite selecting a different item.

cmd.Parameters.Add("@page_id", SqlDbType.Int, 4).Value =
page_id.SelectedItem.Value;
cmd.ExecuteNonQuery();
}
 
G

Guest

Hi,
The problems seems to be with postback. Check if you are rebinding the
dropdownlist on postback also.

HTH
srini
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top