Abdalla Elawad

Abdalla Elawad

  • NA
  • 1k
  • 214.4k

Dropdownlist change value automatically in AutoPostBack

Sep 17 2019 5:14 AM
Hello Programmers
 
I using dropdownlist with autopostback, its working good but if I select a certain value change this value to another value, I have not any update control like panel.
 
what is a problem?
  1. <asp:DropDownList runat="server" Font-Size="Medium" Font-Names="Calibri" CssClass="form-control" Width="250px" Height="30" ID="ddl_device" OnSelectedIndexChanged="ddl_device_SelectedIndexChanged" AutoPostBack="True" >  
  2. <asp:ListItem Value="">Select Items</asp:ListItem>  
  3. <asp:ListItem Value="0">CPU</asp:ListItem>  
  4. <asp:ListItem Value="1">Monitor Extra</asp:ListItem>  
  5. <asp:ListItem Value="1">laptop</asp:ListItem>  
  6. <asp:ListItem Value="1">Printer</asp:ListItem>  
  7. <asp:ListItem Value="1">Fax Machine</asp:ListItem>  
  8. <asp:ListItem Value="1">Scanner</asp:ListItem>  
  9. </asp:DropDownList>
  1. protected void ddl_device_SelectedIndexChanged(object sender, EventArgs e)  
  2. {  
  3. if (ddl_device.SelectedValue == "")  
  4. {  
  5. Response.Write("<script>alert('Please you must be Select Type!');</script>");  
  6. }  
  7. else if (ddl_device.SelectedValue == "1")  
  8. {  
  9. TextBox1.Enabled = true;  
  10. TextBox1.Text = "";  
  11. TextBox2.Enabled = false;  
  12. TextBox2.Text = "";  
  13. TextBox3.Enabled = false;  
  14. TextBox3.Text = "";  
  15. }  
  16. else if (ddl_device.SelectedValue == "0")  
  17. {  
  18. TextBox1.Enabled = true;  
  19. TextBox1.Text = "";  
  20. TextBox2.Enabled = true;  
  21. TextBox2.Text = "";  
  22. TextBox3.Enabled = true;  
  23. TextBox3.Text = "";  
  24. }

Answers (2)