2
Answers

how can i set all the items to dropdownList

Cassie Mod

Cassie Mod

7y
244
1
HI ive got the following code.
 
  1. protected void AdditionalDevice_ItemCommand(object source, RepeaterCommandEventArgs e)  
  2.         {  
  3.             // set all your asp controls (label, ddl, textbox.etc)  
  4.             DropDownList ddlAdditionalDevicesEdit;  
  5.             try  
  6.             {  
  7.                 switch (e.CommandName)  
  8.                 {  
  9.                     case "Edit":  
  10.                         // hide labels  
  11.                         var label = (Label)e.Item.FindControl("lblDeviceType");  
  12.                         var macadreslabel = (Label)e.Item.FindControl("lblMacAdressDevice");  
  13.                         label.Visible = false;  
  14.                         macadreslabel.Visible = false;  
  15.   
  16.                         // set the value of the Label in the ddl  
  17.                         //foreach (var item in AdditionalDevices.Items)  
  18.                         //{  
  19.                         //    var result = (DropDownList)e.Item.FindControl("additionalDeviceDropDownList");  
  20.                         //    ddlAdditionalDevicesEdit.Items.Add(result.SelectedItem.Text);  
  21.                         //}----> not working!!!  
  22.   
  23.                         ddlAdditionalDevicesEdit = (DropDownList)e.Item.FindControl("additionalDeviceDropDownList"); ---> this is showing only one result i need to have all of them  
  24.   
  25.                         // show ddl  
  26.                         ddlAdditionalDevicesEdit.Visible = true;  
  27.   
  28.                         // show textbox  
  29.                         var macAdressTextBox = (TextBox)e.Item.FindControl("deviceMacAdressTextBox");  
  30.                         macAdressTextBox.Text = macadreslabel.Text;  
  31.                         macAdressTextBox.Visible = true;  
  32.   
  33.                         // hide edit_button  
  34.                         ((Button)e.Item.FindControl("additionaldevice_editbutton")).Visible = false;  
  35.   
  36.                         // Hide delete button  
  37.                         ((Button)e.Item.FindControl("additionaldevicedeleteButton")).Visible = false;  
  38.   
  39.                         // show submit_button  
  40.                         ((Button)e.Item.FindControl("additionaldevicesubmitbutton")).Visible = true;  
  41.   
  42.                         // show cancel_button  
  43.                         ((Button)e.Item.FindControl("additionaldeviceCancelButton")).Visible = true;  
  44.   
  45.                         // Hide rows wich are not editted  
  46.                         foreach (RepeaterItem item in AdditionalDevices.Items)  
  47.                         {  
  48.                             if ((item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem) &&  
  49.                                 (e.Item.ItemIndex != item.ItemIndex))  
  50.                             {  
  51.                                 item.FindControl("additionaldevice_editbutton").Visible = false;  
  52.                                 item.FindControl("additionaldevicedeleteButton").Visible = false;  
  53.                             }  
  54.                         }  
  55.   
  56.                         break;  
  57.   
  58.                     case "Submit":  
  59.                         break;  
  60.   
  61.                     case "Delete":  
  62.                        break;  
  63.                 }  
  64.   
  65.             }  
  66.             catch (Exception ex)  
  67.             {  
  68.                 App.HandleException(ex);  
  69.                 ShowFailureText();  
  70.             }  
  71.         }  
However the line   ddlAdditionalDevicesEdit = (DropDownList)e.Item.FindControl("additionalDeviceDropDownList"); is only setting one of the two items to the dropdownlist, how can i add both of them ???
 
thnx  
Answers (2)