Drop down list
-
hi guys i am using asp.net1.1 . i am using dropdownlist,, i have bouned this dropdown with a datasource with data set object, but i want show an empty string on the click event of the clear button, i dont want the data binding to be removed, i just want to show the selected text in the drop down which should be blank string, is there any way ? thanks in advance regards
hello
-
hi guys i am using asp.net1.1 . i am using dropdownlist,, i have bouned this dropdown with a datasource with data set object, but i want show an empty string on the click event of the clear button, i dont want the data binding to be removed, i just want to show the selected text in the drop down which should be blank string, is there any way ? thanks in advance regards
hello
i would recomend to add a default text to the dropdown after binding. dropdownXYZ.DataSource = something; dropdownXYZ.DataValueField = something; dropdownXYZ.DataTextField = something; dropdownXYZ.DataBind(); dropdownXYZ.Items.Add("Select One"); dropdownXYZ.SelectedIndex = ddlEventIDONX.Items.Count-1; // Assuming that you won't be having any negetive value in real time. dropdownXYZ.SelectedItem.Value = "-1"; --- On Clear Button Click event, change the drowndown to "-1" However, i would recommend this clear button to have javascript function. Why should it make an unnecessary round trip to server and waste time even if that is just seconds. --Javascript --- loop thru the document and find all required controls like text box, dropdowns etc and clear it.... ---- var controls = document.all; if(controls[i].tagName == 'INPUT' || controls[i].tagName == 'SELECT' || controls[i].tagName == 'TEXTAREA' || ... etc) if(controls[i].value.length > 0 ) { //Clearing Text Box if(controls[i].tagName == 'INPUT') controls[i].value = ""; //For DropDows else if(controls[i].tagName == 'SELECT' ) { if(controls[i].value != -1) controls[i].value = -1; } else if(controls[i].tagName == 'TEXTAREA') controls[i].value = ""; ----- etc.. } Sreekumar PP
-
i would recomend to add a default text to the dropdown after binding. dropdownXYZ.DataSource = something; dropdownXYZ.DataValueField = something; dropdownXYZ.DataTextField = something; dropdownXYZ.DataBind(); dropdownXYZ.Items.Add("Select One"); dropdownXYZ.SelectedIndex = ddlEventIDONX.Items.Count-1; // Assuming that you won't be having any negetive value in real time. dropdownXYZ.SelectedItem.Value = "-1"; --- On Clear Button Click event, change the drowndown to "-1" However, i would recommend this clear button to have javascript function. Why should it make an unnecessary round trip to server and waste time even if that is just seconds. --Javascript --- loop thru the document and find all required controls like text box, dropdowns etc and clear it.... ---- var controls = document.all; if(controls[i].tagName == 'INPUT' || controls[i].tagName == 'SELECT' || controls[i].tagName == 'TEXTAREA' || ... etc) if(controls[i].value.length > 0 ) { //Clearing Text Box if(controls[i].tagName == 'INPUT') controls[i].value = ""; //For DropDows else if(controls[i].tagName == 'SELECT' ) { if(controls[i].value != -1) controls[i].value = -1; } else if(controls[i].tagName == 'TEXTAREA') controls[i].value = ""; ----- etc.. } Sreekumar PP