Click here to Skip to main content
11,484,162 members (70,679 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET Javascript
I have a drop down ..
<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..

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 11-Feb-13 8:34am
Edited 11-Feb-13 8:36am
ProgramFOX154.7K
v2
Comments
mrinal_kumar_jha at 11-Feb-13 13:36pm
   
As now if i select dropdown zero index , then it automatically select value at 82 index
richcb at 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 at 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.
richcb at 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.
mrinal_kumar_jha at 11-Feb-13 13:44pm
   
my requirement to work on value at zero index now.. so how can i do ?
joshrduncan2012 at 11-Feb-13 13:49pm
   
Rich is correct. You have already coded what you are looking for. What's the problem?
jibesh at 11-Feb-13 13:52pm
   
No Rich is not correct. 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.
mrinal_kumar_jha at 11-Feb-13 14:11pm
   
exactly jibesh
mrinal_kumar_jha at 11-Feb-13 14:20pm
   
please provide solution for this

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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?
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 210
1 Frankie-C 155
2 Raje_ 155
3 OriginalGriff 147
4 Maciej Los 110
0 Sergey Alexandrovich Kryukov 8,489
1 OriginalGriff 7,943
2 Sascha Lefèvre 3,114
3 Maciej Los 2,581
4 Richard Deeming 2,370


Advertise | Privacy | Mobile
Web01 | 2.8.150520.1 | Last Updated 11 Feb 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100