Click here to Skip to main content
12,406,124 members (71,149 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# ASP.NET SQL-Server
i have a field with value "Additional Work" in sql database. But im not able to retrieve the value to dropdownlist. Without spaces it's accepting. how to accept the value with spaces.....
Posted 7-Feb-13 0:12am
Comments
Greysontyrus 7-Feb-13 6:21am
   
Please post the code showing how you are populating the dropdownlist.
Thanks
sukumari1 7-Feb-13 10:05am
   
dropdownlist consists of
<asp:ListItem>Central Board Of Secondary Education
<asp:ListItem>TamilNadu Board Of Higher Secondary
<asp:ListItem>Matriculation Higher Secondary
<asp:ListItem>Anglo Indian

i already inserted the selected value (eg., Anglo Indian) in sql.
Another page has the selected values to be displayed in respective textboxes and dropdownlists.
Now i want Anglo Indian value from sql to be displayed first in the dropdown list
code : txtclass.SelectedValue = (objDataSet.Tables[0].Rows[0]["Class"]).ToString();
manognya kota 7-Feb-13 6:37am
   
How are you populating your dropdown list ?
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

If you want to add elements by seprating with spaces then you can use String.split function and by seprating them by spaces you caan add them to dropdownlist
  Permalink  
Comments
Greysontyrus 7-Feb-13 11:03am
   
This answer does not relate to the question. That is exactly what sukumari1 doesn't want to do
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

There shouldn't be any issue with the
txtclass.SelectedValue = (objDataSet.Tables[0].Rows[0]["Class"]).ToString();
, assuming that txtclass is actually a dropdownlist. Can you check that there are no rogue white spaces at the beginning or end of the list? The values should read <asp:ListItem>Anglo Indian</asp:ListItem>.
Any item you try to select with '.SelectedValue = ' must already be in the list and must be an exact match of the string between the tags
  Permalink  
Comments
sukumari1 9-Feb-13 2:34am
   
Correct. I deleted the space. It's working now.
Thanks.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160726.1 | Last Updated 7 Feb 2013
Copyright © CodeProject, 1999-2016
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