Remove Selected Item from Dropdownlist inside Gridview Using Javascript
Sometime when we use Dropdown inside a gridview there is this requirement of removing the item already selected in a row from the list item of the dropdownlist present in other row..
For Example if we have aaa,bbb,ccc,ddd in a dropdown inside a gridview and we have selected aaa in row1 of the gridview.. Then only bbb,ccc,ddd should display in the dropdown of the other rows..
It can be achieved using foreach loop by finding the selected item in other rows and removing the same..
But Today I am discussing about doing the same using Javascript:
<script language="Javascript"> function checkDuplicate(objID) { //after gridbind put total row count in hidden field iRowCnt = new Number(document.getElementById("hdnRowCount").value); var iCheckedIndex; var dropDownVal; //get selectedvalue in variable var szSelVal = objID.value; for(i = 1; i <= iRowCnt; i++) { dropDownVal = document.getElementById("gvPack_ctl0" + (i + 1) + "_ddl1").value; //compare values if (szSelVal == dropDownVal) { alert("Please, given value alreay selected"); return false; } } </script>
No comments:
Post a Comment
Thank You for Your Comments. We will get back to you soon.