Quantcast
Channel: SharePoint 2010 - Development and Programming forum
Viewing all articles
Browse latest Browse all 11571

Reset Dropdown list in sharepoint webpart

$
0
0

Hello Techies,
I have a webpartwhere there are fields like:

  • Year(DropDown)
  • Month(DropDown)
  • Employer(txtbox)
  • CTClakhs(txtbox)
  • CTCthousand(txtbox)
  • Currency(Dropdown)

Here i got the requirement like if Year and Month values are "0" then I need to disable and reset the values of other fields say Employer,CTClakhs,CTCThousandsand Currency
so for this I wrote the validations in javascript which are called onChange event of Year and Month dropdowns

 function clearFunction() {

        if (document.getElementById('ctl00_PlaceHolderMain_form1_ddlYears').value == 0 && document.getElementById('ctl00_PlaceHolderMain_form1_ddlMonth').value == 0) {
            document.getElementById('ctl00_PlaceHolderMain_form1_txtEmployer').value = "";
            document.getElementById('ctl00_PlaceHolderMain_form1_txtLacs').value = "";
            document.getElementById('ctl00_PlaceHolderMain_form1_txtThousand').value = "";
            document.getElementById("ctl00_PlaceHolderMain_form1_ddlCurrency").selectedIndex = 0;
            //document.getElementById("ctl00_PlaceHolderMain_form1_ddlCurrency").value = 0;
            document.getElementById('ctl00_PlaceHolderMain_form1_txtEmployer').disabled = true;
            document.getElementById('ctl00_PlaceHolderMain_form1_txtLacs').disabled = true;
            document.getElementById('ctl00_PlaceHolderMain_form1_txtThousand').disabled = true;
            document.getElementById("ctl00_PlaceHolderMain_form1_ddlCurrency").disabled = true;

        }
        else {

                            document.getElementById('ctl00_PlaceHolderMain_form1_txtEmployer').disabled = false;
                            document.getElementById('ctl00_PlaceHolderMain_form1_txtLacs').disabled = false;
                            document.getElementById('ctl00_PlaceHolderMain_form1_txtThousand').disabled = false;
                            document.getElementById('ctl00_PlaceHolderMain_form1_ddlCurrency').disabled = false;

        }

But here values of all the fields are getting reset except Currency dropdown 
Later I check the value of Currency through console and the value was getting reset but it was not reflected in UI (still shows selected value)

Here I wanted to reset the value of Currency dropdown :( :( 

Again for this i tried to achieve .cs file and made the change on .ascx file like

<asp:UpdatePanel ID="OuterUpdatePanel" runat="server"  UpdateMode="Conditional"><ContentTemplate><tr class="contactForm twoSelects"><td><label for="exp">
                Total Experience <span class="required"></span></label></td><td class="selector" id="uniform-undefined"><div><asp:DropDownList ID="ddlYears" CssClass="uniformselect" onSelectedindexChanged="drp_Commoncleardata" autopostback="true"  runat="server" Width="100%"
                    BackColor="Transparent"></asp:DropDownList></div><div><asp:DropDownList ID="ddlMonth"  CssClass="uniformselect" onselectedindexchanged="drp_Commoncleardata" autopostback="true"  runat="server" Width="100%"
                    BorderStyle="None"><asp:ListItem Value="-1">-- In Months -- </asp:ListItem><asp:ListItem Value="0">0 </asp:ListItem><asp:ListItem Value="1">1</asp:ListItem><asp:ListItem Value="2">2</asp:ListItem><asp:ListItem Value="3">3</asp:ListItem><asp:ListItem Value="4">4</asp:ListItem><asp:ListItem Value="5">5</asp:ListItem><asp:ListItem Value="6">6</asp:ListItem><asp:ListItem Value="7">7</asp:ListItem><asp:ListItem Value="8">8</asp:ListItem><asp:ListItem Value="9">9</asp:ListItem><asp:ListItem Value="10">10</asp:ListItem><asp:ListItem Value="11">11</asp:ListItem></asp:DropDownList></div></td></tr><tr class="contactForm"><td><label for="org">
                Current Organization <!--<span class="required"></span>--></label></td><td><asp:TextBox ID="txtEmployer" runat="server" CssClass="textbox" MaxLength="50" BackColor="Transparent"></asp:TextBox></td></tr><tr class="contactForm"><td></td><td colspan="2"><label style="width: 250px !important;"><!--(Enter NA in case of fresher)--></label></td></tr><tr class="contactForm"><td><label for="CTC">
                Current Compensation (CTC) <!--<span class="required"></span>--></label></td><td><asp:TextBox ID="txtLacs" onkeypress="return numbersonly(event, false)" runat="server"
                CssClass="textbox_CTC" MaxLength="10" BackColor="Transparent"></asp:TextBox>&nbsp;&nbsp;&nbsp;<span
                    class="field_Desc">Lacs</span> &nbsp;&nbsp;<asp:TextBox ID="txtThousand" onkeypress="return numbersonly(event, false)" runat="server"
                CssClass="textbox_CTC" MaxLength="10"></asp:TextBox><br />&nbsp;&nbsp;&nbsp;<span class="field_Desc">Thousand</span></td></tr><tr class="contactForm"><td><label for="currency">
                Currency</label></td><td><asp:DropDownList ID="ddlCurrency" runat="server"  CssClass="combobox_new uniformselect"  Width="100%"  BackColor="Transparent" ></asp:DropDownList></td></tr></ContentTemplate><Triggers><asp:AsyncPostBackTrigger ControlID="ddlYears" EventName="SelectedIndexChanged" /><asp:AsyncPostBackTrigger ControlID="ddlMonth" EventName="SelectedIndexChanged" /></Triggers></asp:UpdatePanel>

.cs code 

protected void drp_Commoncleardata(object sender, EventArgs e)
        {
            if ((ddlMonth.SelectedValue == "0") && (ddlYears.SelectedValue == "0"))
            {
                ddlCurrency.ClearSelection();
            }

        }

the above code is also not helping me 
Please help and let me know what needs to be done to reset DropDown selection 




Viewing all articles
Browse latest Browse all 11571

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>