Forums » .NET » ASP.NET »

dropdownlist selected value


Posted Date: 26 May 2005      Posted By:: Ashok     Member Level: Gold    Member Rank: 631     Points: 2   Responses: 5



i have a senario where i need to load the dropdownlist with the data from the datasource . When the dropdownlist is loaded i need to select the selected value to a user previously selected value. For example
i have a dropdownlist has all states such as NJ,NY,PA . But, in our database the user already have selected NY from this selection before. Now when i load this dropdownlist again i want to have this 'NY' selected as the first value in the dropdownlist. Can anyone please help me ?????/




Responses

#20096    Author: Sadha Sivam      Member Level: Gold      Member Rank: 0     Date: 26/May/2005   Rating: 2 out of 52 out of 5     Points: 2

Hi,

Before calling the databind function. get the value selected and store it in some temp variable. After the databind function. Run a loop which will traverse through the entire items check for value and make ur selection.

With regards,

Sadha Sivam S,

<center>
<a href="http://groups.yahoo.com/group/dotnetanswersfromsadha/join">
<img src="http://us.i1.yimg.com/us.yimg.com/i/yg/img/i/us/ui/join.gif" border="0"
alt="Click here to join dotnetanswersfromsadha"><br>Click to join dotnetanswersfromsadha</a>
</center>


 
#20104    Author: Anil Rajan      Member Level: Gold      Member Rank: 0     Date: 27/May/2005   Rating: 2 out of 52 out of 5     Points: 2

hi
try this

DropDownList1.SelectedValue = Convert.ToString(DropDownList1.Items.FindByText("NY").Value) ;

hope it helps


 
#20232    Author: Ashok      Member Level: Gold      Member Rank: 631     Date: 27/May/2005   Rating: 2 out of 52 out of 5     Points: 2

i tried it with
DropDownList1.SelectedIndex = Convert.ToString(DropDownList1.Items.FindByText("NY").Value)


i am getting an error

Input string was not in a correct format.


i think it is becasue i am assigning "NY" to the integer value index.


Can you advise me on it





 
#20233    Author: Ashok      Member Level: Gold      Member Rank: 631     Date: 27/May/2005   Rating: 2 out of 52 out of 5     Points: 2

Hi,
SADA
can you give me the code for looping through in dropdownlist


Thank you


Ranju


 
#20278    Author: Anil Rajan      Member Level: Gold      Member Rank: 0     Date: 27/May/2005   Rating: 2 out of 52 out of 5     Points: 2

dear friend ,
please recheck my code

its not "DropDownList1.SelectedIndex" but
"DropDownList1.SelectedValue"

DropDownList1.SelectedValue = Convert.ToString(DropDownList1.Items.FindByText("NY").Value) ;

it works try it


 
Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.



Previous : Validation Controls
Return to Discussion Forum
Post New Message
Category: ASP.NET

Subscribe to Subscribers
Awards & Gifts
Talk to Webmaster Tony John

Online Members

Zirinsky
More...
Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India