Problem with Webcontrols.dropDownList

V

VMI

My Web dropdownlist with AutoPostback equal to true has code in its
SelectedIndexChanged Event . When I change the dropdownlist value and the
SelectedIndexChanged Event is executed, the page does a Refresh, puts the
initial value back into the dropdownlist, and then runs SelectedIndexChanged
with that initial value (not the one I selected). How come?

Thanks.
 
S

Siva M

Very likely that you are populating the dropdown box on postback also. Make
sure you fill the drop-down only on inital page load.

if (!IsPostBack)
{
// Fill drop-down
}

My Web dropdownlist with AutoPostback equal to true has code in its
SelectedIndexChanged Event . When I change the dropdownlist value and the
SelectedIndexChanged Event is executed, the page does a Refresh, puts the
initial value back into the dropdownlist, and then runs SelectedIndexChanged
with that initial value (not the one I selected). How come?

Thanks.
 
V

VMI

That worked, but during the Page Load I fill up a dataview. On postback,
the dataview is erased so I can't use it in other events. I found a solution
for this, but I'm not sure if it's the right procedure:

private void Page_Load(object sender, System.EventArgs e)
{
ZM_Utilities.Utilities myUtils = new ZM_Utilities.Utilities();
string sQuery = "col_name like '*'";
if (!IsPostBack)
{
_view_buildings = myUtils.fillBuildingsTable(sQuery, "WEB"); //fill
View with data
this.DropDownList_buildings.DataSource = _view_buildings;
this.DropDownList_buildings.DataTextField = "col_name"; //so it only
displays one column of the dataview
this.DropDownList_buildings.DataBind();
}
_view_buildings = myUtils.fillBuildingsTable(sQuery, "WEB"); // Fill
view again on postback. IS this the right way?
}


Thanks.
 
S

Siva M

It's fine because _view_buildings is not persisted across postbacks.

That worked, but during the Page Load I fill up a dataview. On postback,
the dataview is erased so I can't use it in other events. I found a solution
for this, but I'm not sure if it's the right procedure:

private void Page_Load(object sender, System.EventArgs e)
{
ZM_Utilities.Utilities myUtils = new ZM_Utilities.Utilities();
string sQuery = "col_name like '*'";
if (!IsPostBack)
{
_view_buildings = myUtils.fillBuildingsTable(sQuery, "WEB"); //fill
View with data
this.DropDownList_buildings.DataSource = _view_buildings;
this.DropDownList_buildings.DataTextField = "col_name"; //so it only
displays one column of the dataview
this.DropDownList_buildings.DataBind();
}
_view_buildings = myUtils.fillBuildingsTable(sQuery, "WEB"); // Fill
view again on postback. IS this the right way?
}


Thanks.
 

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

Top