473,324 Members | 2,417 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

DROPDOWNLIST databound and unbound

35
i have a confusion
please help me with the reason
in my ASP.NET web page i have two drop down list
DropDownLis1 is unbound and DropDownList2 is data bound to my table named Employee

Expand|Select|Wrap|Line Numbers
  1. //unbound (items are Apples,Oranges,Grapes,Fruits)
  2. string s="",str="";
  3. foreach (ListItem li in DropDownList1.Items) 
  4.         {
  5.            bool b = li.Text.Equals("Apples");   //true for Apples
  6.             str += b;  //true for Apples
  7.             if (b) //li.Text.Equals("Apples"))
  8.             {
  9.               s += " the Selection is " + li.Text+" ";
  10.             }
  11.             s += li.Text;
  12.         }
  13.         Label1.Text = s +" str "+str;
  14.  
Expand|Select|Wrap|Line Numbers
  1. //bound ( Employee table has employee names //Femina,ramya,jyothi,Nilafer,Fayaz)
  2. string ss = "";
  3.        foreach (ListItem li in DropDownList2.Items)
  4.        {
  5.         bool b = li.Text.Equals("Femina"); //here its never true but dont know why
  6.  
  7.             if (li.Text.Equals("Femina")) //not executed at all 
  8.             {
  9.                 ss += " selection is " + li.Text +" ";
  10.             }
  11.             ss += li.Text;
  12.         }
  13.         Label4.Text += ss;
  14.  
so in these two DDLs DropDownList1 works fine
but the DropDownList2 never returns true when it compares against Femina please help me with the reason behind this
sorry for the lengthy question and thanks in advance
Aug 21 '08 #1
6 2357
cloud255
427 Expert 256MB
Off the top of my head, string.equals() is case sensitive, so check for that. maybe making everything lower case will help:

Expand|Select|Wrap|Line Numbers
  1. bool b = ls.Text.toLower().Equals(testString.toLower());
Aug 21 '08 #2
femina
35
i checked it out sir(with my Employee table also),
its Femina only
no problem with the case
Aug 21 '08 #3
cloud255
427 Expert 256MB
Is it possible that "Femina", your first entry, is not part of the dataset which is returned from the database? Have you created a break point before the loop starts and verified that "Femina" is indeed in in the drop down list?

It's very strange that all the other names work and this one doesn't ...
Aug 21 '08 #4
femina
35
sir i sorted out the problem
my SQLSERVER Employee table had empname datatype as nchar(10)
so Femina had still 4 spaces after the word
i changed it to nvarchar(25) and the problem was sorted out
thanks for the attention given to my question
Aug 22 '08 #5
r035198x
13,262 8TB
sir i sorted out the problem
my SQLSERVER Employee table had empname datatype as nchar(10)
so Femina had still 4 spaces after the word
i changed it to nvarchar(25) and the problem was sorted out
thanks for the attention given to my question
Some people make it a point to always TRIM the data before any string comparisons.
Aug 22 '08 #6
femina
35
so my table design also does not need to be modified
thanks so much
Aug 22 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Shiju Poyilil | last post by:
Hi ! I have a requirement wherein i am binding a datalist which contains a label (Caption for the field) and some literal hidden fields and a dropdown list. When I am binding to the datalist.....
1
by: Joe Gass | last post by:
I'd like to bind some xml to a dropdownlist <engines> <engine name="test1" id="1" /> <engine name="test2" id="2" /> </engines> If I do: ddlEngines.DataSource =...
0
by: Veraamalia | last post by:
I cannot get the SelectedValue from databound dropdownlist. The selectedValue always return the same value. But I have no problem with unbound dropdownlist. Thank U
6
by: Dabbler | last post by:
I have a dropdownlist in a GridView ItemTemplate. I need to bind the ddl to an SqlDataSource, then have a value from a boundfield in the row be passed as the keyfield for select where clause. Im...
2
by: cider123 | last post by:
I have a SqlDataSource bound to a DropDownList Combo. Works just fine. I noticed 2 properties you can set in the DropDownList, 1 for the value to be displayed in the "Text" column and 1 for the...
3
by: podi | last post by:
Hi, I just wonder if there is a way to set a selected item in dropdown list which items are retreived from database without touching c# code ? I mean, i have in gridview, in edit mode one...
2
by: Cirene | last post by:
In my databound datagrid i have a databound dropdownlist, like this: <asp:DropDownList ID="ddlAvail0" runat="server" SelectedValue='<%# Bind("AvailMon") %>'> <asp:ListItem></asp:ListItem>...
1
by: Brett | last post by:
I have a DropDownList in an ASP.NET web form that is populated with items from a lookup table by binding that DropDownList to a SqlDataSource. However, the items in the lookup table can change over...
3
by: E. Kwong | last post by:
I have a DropDownList which is originally bound to a SqlDataSource. In Design view, the control is shown as "Databound". Later I changed my mind and changed the dropdown binded to a datatable...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.