Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. inactive one dropdownlist while we select item in another dropdown list

inactive one dropdownlist while we select item in another dropdown list

Scheduled Pinned Locked Moved ASP.NET
help
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    subbu sk
    wrote on last edited by
    #1

    Hi all, i need to inactive one dropdownlist while we select item "Photo prints " in another dropdown list. and i need to display a text in txtcomment "My order is of minimum Rs. 2,500.". i am sending my code pls help me... If Not Page.IsPostBack Then Me.ddlproduct.Items.Add("Select") Me.ddlproduct.Items.Add("Photo Prints") 'If Me.ddlproduct.SelectedValue = "Photo Prints" Then ' 'Me.ddlquantity.Enabled = False ' txtcomment.Text = "My order is of minimum Rs. 2,500." 'End If Me.ddlproduct.Items.Add("Custom Calendars") Me.ddlproduct.Items.Add("Collage Posters") Me.ddlproduct.Items.Add("Greeting Cards") Me.ddlproduct.Items.Add("Photo Mugs") Me.ddlproduct.Items.Add("Zoomini Books") Me.ddlproduct.Items.Add("Zoomin T-Shirts") Me.ddlquantity.Items.Add("Select") Me.ddlquantity.Items.Add("30-50") Me.ddlquantity.Items.Add("51-100") Me.ddlquantity.Items.Add("101 & Above") End If and Protected Sub ddlproduct_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlproduct.SelectedIndexChanged If Me.ddlproduct.SelectedValue = "Photo Prints" Then Me.ddlquantity.Enabled = False txtcomment.Text = "My order is of minimum Rs. 2,500." End If End Sub

    Thanks Subbu.

    C N 2 Replies Last reply
    0
    • S subbu sk

      Hi all, i need to inactive one dropdownlist while we select item "Photo prints " in another dropdown list. and i need to display a text in txtcomment "My order is of minimum Rs. 2,500.". i am sending my code pls help me... If Not Page.IsPostBack Then Me.ddlproduct.Items.Add("Select") Me.ddlproduct.Items.Add("Photo Prints") 'If Me.ddlproduct.SelectedValue = "Photo Prints" Then ' 'Me.ddlquantity.Enabled = False ' txtcomment.Text = "My order is of minimum Rs. 2,500." 'End If Me.ddlproduct.Items.Add("Custom Calendars") Me.ddlproduct.Items.Add("Collage Posters") Me.ddlproduct.Items.Add("Greeting Cards") Me.ddlproduct.Items.Add("Photo Mugs") Me.ddlproduct.Items.Add("Zoomini Books") Me.ddlproduct.Items.Add("Zoomin T-Shirts") Me.ddlquantity.Items.Add("Select") Me.ddlquantity.Items.Add("30-50") Me.ddlquantity.Items.Add("51-100") Me.ddlquantity.Items.Add("101 & Above") End If and Protected Sub ddlproduct_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlproduct.SelectedIndexChanged If Me.ddlproduct.SelectedValue = "Photo Prints" Then Me.ddlquantity.Enabled = False txtcomment.Text = "My order is of minimum Rs. 2,500." End If End Sub

      Thanks Subbu.

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      This is ugly, but I'd expect it to work, so long as the autopostback on the control is true. I'd do this in javascript tho, not via a postback. It's hard to know what's wrong when you don't tell us what happens when you try to use the code. Does the event fire ? In the debugger, does Me.dllproduct.SelectedValue equal what you expect ? Is the issue that you never reenable dllquantity and clear txtcomment, if something else is selected ?

      Christian Graus Driven to the arms of OSX by Vista.

      1 Reply Last reply
      0
      • S subbu sk

        Hi all, i need to inactive one dropdownlist while we select item "Photo prints " in another dropdown list. and i need to display a text in txtcomment "My order is of minimum Rs. 2,500.". i am sending my code pls help me... If Not Page.IsPostBack Then Me.ddlproduct.Items.Add("Select") Me.ddlproduct.Items.Add("Photo Prints") 'If Me.ddlproduct.SelectedValue = "Photo Prints" Then ' 'Me.ddlquantity.Enabled = False ' txtcomment.Text = "My order is of minimum Rs. 2,500." 'End If Me.ddlproduct.Items.Add("Custom Calendars") Me.ddlproduct.Items.Add("Collage Posters") Me.ddlproduct.Items.Add("Greeting Cards") Me.ddlproduct.Items.Add("Photo Mugs") Me.ddlproduct.Items.Add("Zoomini Books") Me.ddlproduct.Items.Add("Zoomin T-Shirts") Me.ddlquantity.Items.Add("Select") Me.ddlquantity.Items.Add("30-50") Me.ddlquantity.Items.Add("51-100") Me.ddlquantity.Items.Add("101 & Above") End If and Protected Sub ddlproduct_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlproduct.SelectedIndexChanged If Me.ddlproduct.SelectedValue = "Photo Prints" Then Me.ddlquantity.Enabled = False txtcomment.Text = "My order is of minimum Rs. 2,500." End If End Sub

        Thanks Subbu.

        N Offline
        N Offline
        Nishant Singh
        wrote on last edited by
        #3

        Hi Subbu , You could very well use javascript for this purpose ,it will prevent uneccesery post back, but if at all you are doing it in code behind then it seems fine except for part

        subbu.sk wrote:

        'If Me.ddlproduct.SelectedValue = "Photo Prints" Then ' 'Me.ddlquantity.Enabled = False ' txtcomment.Text = "My order is of minimum Rs. 2,500." 'End If

        which is not required (anyways it is commented) I recommend you implement this in JavaScript On Code behind u just need to add attribute (In Page load Event)

        ddlproduct.Attibutes.Add("onchange","CheckDropDown();")

        In on client Side you need to define this function "CheckDropDown();"

        function CheckDropDown()
        {
        var ddlproduct=document.getElementById("ddlproduct");
        var ddlquantity=document.getElementById("ddlquantity");
        var txtComment=document.getElementById("txtComment");
        var selIndex=ddlproduct.selectedIndex;
        var optValue=ddlproduct.options[selIndex].value;
        if(optValue=='Photo Prints')
        {
        ddlquantity.disabled=true;
        txtComment.Value='My order is of minimum Rs. 2,500';
        }
        else
        { ddlquantity.disabled=false
        txtComment.Value='';
        }
        }

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups