DropdownList.selectedIndex always 0 (yes, I do have !isPostBack)

限于喜欢 提交于 2019-11-29 10:51:09

When the DataList is data-bound, the AutoPostBack has not been handled yet, i.e. the values in the ItemCreated event are still the original values.

You need to handle the SelectedIndexChange event of the dropdown control.

Regarding your 2nd question:

I suggest you remove the AutoPostBack from the dropdown, add an "Update" button, and update the data in the button Click event.

The button can hold Command and CommandArgument values, so it's easy to associate with a database record.

user4132142

Thank You for your solution

 protected void ddlOnSelectedIndexChanged(object sender, EventArgs e) {
     try {
         ModalPopupExtender1.Show();
         if (ViewState["Colors"] != null) {
             FillColors(ViewState["Colors"].ToString());
         }

         DropDownList dropDownListColor = (DropDownList)sender;
         DataListItem dataListItem = (DataListItem)dropDownListColor.Parent;

         Image image = (Image)dataListItem.FindControl("mdlImage");
         Label ProductCode = (Label)dataListItem.FindControl("lblprdCode");
         Label ProductName = (Label)dataListItem.FindControl("lblProdName");
         DropDownList ddlQuantity = (DropDownList)dataListItem.FindControl("ddlQuantity");
         Label ProductPrice = (Label)dataListItem.FindControl("lblProdPrice");
         Label TotalPrice = (Label)dataListItem.FindControl("lblTotPrice");
         //Label ProductPrice = (Label)dataListItem.FindControl("lblProdPrice");
     } catch (Exception ex) {

     }
 }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!