Using DropDownList bound data pages in ascx to refresh time-varying empty problems

Source: Internet
Author: User

Phenomenon:

In the ascx user control, there is a DropDownList that is first entered on this page to bind and display the data normally. Switch a few pages, or point a few other links, and then look at this DropDownList, is empty.

Solve:

Only need to put the DropDownList binding to! In Page.isnotpostback, such as:

if (! Page.IsPostBack)

{

DropDownList ddlproject = Formview1.findcontrol ("Ddlproject") as DropDownList;

DdlProject.Items.Clear ();

foreach (Project information item in coll)

{

DDLPROJECT.ITEMS.ADD (new ListItem (item). ProjectName, item. Projectid.tostring ()));

}

if (DdlProject.Items.Count > 0)

{

for (int i = 0; i < DdlProject.Items.Count; i++)

{

if (ddlproject.items[i). Value = = this. ProjectID)

{

Ddlproject.selectedindex = i;

Break

}

}

}

}

http://four-corner.appspot.com/

====2010-3-2 Update:

I'm sorry. To find the real problem.

DropDownList data binding should be processed in the DataBound event that contains this DropDownList FormView.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.