Populating drop down list when the page is loaded

If you populate the drop down list in the page_load event, when ever the page gets posted back the drop down list gets populated.

To avoid this you can use the post back property.


if(!page.ispostback)
{
//here you can populate the drop down list.
}


Comments

Author: nirav14 Apr 2010 Member Level: Gold   Points : 1

for that,


if(!IsPostBack)
{
/*
Write code here for sqlconnection and sqldataadapter and dataset

*/
DropDownList1.DataSource = ds;
DropDownList1.DataTextField="EmpName"

DropDownList1.DataValueField="EmpID";

DropDownList1.DataBind();
}



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: