从下拉列表中填充 asp.net 表单



我的选定索引 从我的下拉列表中更改,显示我的列表项,但仅在选择任何列表项以填充表单时显示顶部列表项。今天早些时候它工作正常(也许我在没有注意到的情况下更改了一些东西(,现在它不起作用。

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;
}

如果我猜到这一点 - 您必须在Page_Load事件中绑定DropDownList。将该代码包装在Page.IsPostBack Check中,如下所示。

if (!Page.IsPostBack)
{
DropDownListBind();//here goes your binding code
}

最新更新