inactive one dropdownlist while we select item in another dropdown list
-
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.
-
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.
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.
-
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.
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='';
}
}