473,327 Members | 1,892 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,327 software developers and data experts.

Comparing dropdownlist null item

I have a combobox with values binded from a database
I add an empty item in the first index
Expand|Select|Wrap|Line Numbers
  1. ddlFichaTipo.DataBind();
  2. ListItem emptyitem = new ListItem(null, null);
  3. ddlFichaTipo.Items.Insert(0, emptyitem);
  4.  
then i need to check if the item selected is not that one
Expand|Select|Wrap|Line Numbers
  1. if(ddlFichaTipo.SelectedValue != null)
  2. gridselect += " and ficha.FichatipoID = " + ddlFichaTipo.SelectedValue;
  3.  
The condition is always true whatever the item is selected. What's wrong?...

ddlfichatipo is my drop down list.
Jun 4 '10 #1

✓ answered by Plater

Selected value is probably an empty string.
Did you set a breakpoint and actually look what SelectedValue IS when your empty item is selected?
Why not use SelectedIndex or SelectedItem or the other more useful properties?

9 3542
Plater
7,872 Expert 4TB
Selected value is probably an empty string.
Did you set a breakpoint and actually look what SelectedValue IS when your empty item is selected?
Why not use SelectedIndex or SelectedItem or the other more useful properties?
Jun 4 '10 #2
Actually I changed the condition to
Expand|Select|Wrap|Line Numbers
  1. if (ddlFichaTipo.SelectedIndex != 0)
  2.  
and didn't change a thing... I'm not able to debbug my program actually...
Jun 4 '10 #3
Plater
7,872 Expert 4TB
You cannot debug it? Is it for an embded system or something?
Jun 4 '10 #4
GaryTexmo
1,501 Expert 1GB
You can always debug your program :) If it's a matter of not having visual studio you can always put logging in. Something I typically do is create a new form with a textbox on it and use it to log messages.

In fact, I think I'll write a quick insight on it :) Check that section in a bit.

That said, you can also very easily get Visual Studio. Express Edition (2008 and 2010) is available as a free download from Microsoft. I'd recommend it unless you're unable to for other reasons.
Jun 4 '10 #5
Yes I do have Visual studio indeed. But actually i'm putting breakpoints and it just dont stop. Yes, I know how to put a breakpoint and I think there isn't anything disabling it... I do laugh at myself xD
Jun 4 '10 #6
Well i solved my problem in a weird way but it's working... xD. Thank's for the tips
Jun 4 '10 #7
Plater
7,872 Expert 4TB
What turned out to be the solution/issue?
Jun 4 '10 #8
Assigned other events althougth it's not perfect neither the best way of doing it. Ill try to find other one soon.

it's doesn't recognise the item after the empty one.
Jun 4 '10 #9
Woot got it just too dummy i was calling a remove duhh xD

Just put the first code on the pre render event of dropdownlist and its done.
Thanks again.
Jun 4 '10 #10

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

Similar topics

4
by: Paul Lyons | last post by:
Not sure how I've not come across this before... I've overloaded operator == for one of my classes using the following code. public static bool operator ==(Stock x, Stock y) { return...
0
by: 00_CumPeeWearD12 | last post by:
How to add background color to DropDownList item? I can do this in HTML: <select> <option>test1 <option style='background:red'>test2 <option>test3 </select>
4
by: dhnriverside | last post by:
Hi guys I've got a dropdownlist which is being databound to an sqldatareader at runtime. I want to add an extra Item to the list, not from the database. I know I can do this with ...
2
by: Jeff User | last post by:
Hi C# .NET1.1 I have read Visual Studio help and several articles on the web. Obviously this is a common topic. However, I see this code over and over yet I am stuck with the FindControl method...
1
by: g | last post by:
I have a user control that contains a dropdownlist. Using a public property, I can get the selected item. However, I am unsure of how to use that same public property to set the selected item. ...
2
by: Derek Vincent | last post by:
Using Visual Studio.net 2003 to create an aspx web form I am having a problem selecting an item from DropDownListBox with id= ListBoxStudies. I can see the items from the bound database table but...
1
by: John | last post by:
If you set DropDownList.SelectedValue to an item not in the list, shouldn't an exception be thrown? ie: <asp:DropDownList ID="DropDownList1" runat="server"> <asp:ListItem Text="1"...
1
by: sean.polacsek | last post by:
Hi there, I have a curious problem. I have DropDownList that gets bound to datatable during PreRender. Straight after binding I set the SelectedValue of the DropDownList. When the page is...
1
by: rockdale | last post by:
Hi, all Is there a way to dynamically attach a regularexpressionvalidator to a textbox base on dropdownlist selected item? Let's say I have a dropdownlist list all contact type - phone, cell,...
15
OuTCasT
by: OuTCasT | last post by:
Please help i have this query that works with drop downlist selections on a page to search for the information selected in the listboxes. but having a problem when the selection is "null" ...
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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
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
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.