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

后端 未结 4 1298
萌比男神i
萌比男神i 2020-12-19 10:38

(Scroll down to bottom of post to find solution.)

Got a asp.net page which contains a Datalist. Inside this datalist, there is a template containing

相关标签:
4条回答
  • 2020-12-19 11:01

    some MSDN links with C# examples on bubbling

    http://msdn.microsoft.com/en-us/library/system.web.ui.control.onbubbleevent.aspx

    http://msdn.microsoft.com/en-us/library/aa719644(VS.71).aspx

    http://msdn.microsoft.com/en-us/library/aa720044(VS.71).aspx

    0 讨论(0)
  • 2020-12-19 11:03

    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.

    0 讨论(0)
  • 2020-12-19 11:09

    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.

    0 讨论(0)
  • 2020-12-19 11:26

    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) {
    
         }
     }
    
    0 讨论(0)
提交回复
热议问题