简体   繁体   中英

Populating asp.net form from drop down list

My Selected Index Changed from my drop down list, displays my list items, but will only display the top list item when any of the list items are selected to populate the form. It was working fine earlier today (perhaps I have changed something without noticing) and now it does not work.

 protected void ddlEdit_SelectedIndexChanged(object sender, EventArgs e)
{
    Book b = catalogueInstance.books[ddlEdit.SelectedIndex];
    txtID.Text = b.id.ToString();
    txtTitle.Text = b.title;
    txtAuthor.Text = b.author;
    txtYear.Text = b.year.ToString();
    txtPublisher.Text = b.publisher;
    txtISBN.Text = b.isbn;
}

If i was to guess this--You must be binding the DropDownList in the Page_Load event. Wrap that code inside Page.IsPostBack Check like below.

if (!Page.IsPostBack)
   {

      DropDownListBind();//here goes your binding code
   }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM