Click here to Skip to main content
15,893,266 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a drop down ..
ASP
<asp:DropDownList ID="ddlPD1" DataTextField="vc_pd_far_value" DataValueField="in_pd_far_id"
                    Width="55" runat="server" Enabled="true" onclick="SetDefaultPDValue(this);" />



and function to set default size to 82 index..

C#
function SetDefaultPDValue(selPD) {
   if(selPD.options[0].selected)
   {
     selPD.options[82].selected = true;
   }
 }


now i have requirement to select value at zero index .. how to do ??

[Edit]Code block added[/Edit]
Posted
Updated 11-Feb-13 7:36am
v2
Comments
k@ran 11-Feb-13 13:36pm    
As now if i select dropdown zero index , then it automatically select value at 82 index
Richard C Bishop 11-Feb-13 13:40pm    
Why is that a suprise? That is exactly what you have coded. You are setting the index to 82 if 0 is selected.
Jibesh 11-Feb-13 13:52pm    
The problem is OP added this checking to the DropDown onClick event which fires every time user clicks on it, and if the user choose index 0, it automatically select index 82 there by restricting the user to select index 0. but what OP wants here is index 82 must be selected by default later user can select any index he prefer.
Richard C Bishop 11-Feb-13 13:56pm    
I agree with you, my question/comment was directly toward the comment the OP posted first. I read it as if the OP was confused about why they were getting the result they were.
k@ran 11-Feb-13 13:44pm    
my requirement to work on value at zero index now.. so how can i do ?

1 solution

move the default setting of index 82 as selected from this method SetDefaultPDValue to some other initialize routine. If you put this code in the onClick method when ever use select index 0 it automatically selects index 82.

am not a ASP expert so cant say what is the initialize routine. may be you have pageload method?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900