?
Solved

selectedValue property in dropdownlist of detailsview??

Posted on 2008-10-20
8
Medium Priority
?
615 Views
Last Modified: 2012-05-05
Hi,

I am having a little problem with the NULL and emtpy value of the records from the database.
I am trying to bind a dropdownlist to the detailsview in edit mode.
I am getting the selectedvalue is not in the list item of values.

The dropdownlist  values come from dstatus field of table1(id,dstatus).
The dstatus field has the following values (active,inactive,pass,fail).
the values of detailsview come from this table called table2(id,name,status)

I want to put a dropdown in edit mode of detailsview.

The status field contains both null and empty values including active,inactive,pass,fail.
How do I need to handle the null and empty?

<asp:DropDownList ID="DropDown1" runat="server" SelectedValue='<%# Bind("status") %>'
DataValueField="dstatus" DataTextField="dstatus" AppendDataBoundItems="True" DataSourceID="DSdStatus">
<asp:ListItem value=''></asp:ListItem>
</asp:DropDownList>

The Dropdownlist basically has the following values:active,inactive,pass,fail.
The values of status in the table2 are active,inactive,pass,fail, NULL and EMPTY.
Since NULL and EMPTY values are not in the dropdownlist, it is erroring out.
How do I need to handle this??
0
Comment
Question by:dkim18
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 16

Expert Comment

by:GreymanMSC
ID: 22762548
How are you filling the Datasource?

Your Datasource needs to include a record for all possible selectedvalues, including null.  I generally do this using a union query.


<asp:SqlDatasource Id=DSdStatus  Runat=Server
  ...
  SelectCommand="Select t.id, t.status from table2 t union select null as id, '-select-' as status order by status;"
  ></asp:SqlDatasource>

Open in new window

0
 

Author Comment

by:dkim18
ID: 22762779
OK.
Thanks for that. I will try that.

Funny thing is I am getting the error from when status field has a value.
Say, the status field has a value of 'active' and I would like to edit it so I click the edit link. Then it errors out saying that the selectedvalue is invalid because it doesn't exit in the list of items.

I thought I got this dropdownlist in detailsview in edit mode all working.
Today I was testing and I am getting this error and I don't know what problem is.
I looked at it all day today.
0
 
LVL 16

Expert Comment

by:GreymanMSC
ID: 22762921
Both your DataValueField and DataTextField are dstatus.  How are your tables linked?  Is it not on table2.status=table1.id?  If so, your DataValueField would need to be the id key.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:dkim18
ID: 22767122
Hi,

I am using the table1 as a general lookup table for my dropdowns.
Mine is pretty simple table so I haven't linked them.
I am just storing the value in the table 2 like table2.status = table1.dstatus.

I don't know understand why it is saying the selectedvalue is not in the list of items...
0
 

Author Comment

by:dkim18
ID: 22768007
I just cannot figure this out.
SelectedValue is one of the list items but it is telling me that it is not one of the items.

When edit on the empty status, it loads the dropdown OK.
But when the value is in that field, the selectedvalue comes out invalid.

What gives?? It is really frustrating. It shouldn't be this difficult to put a simple dropdownlist.
0
 

Author Comment

by:dkim18
ID: 22769566
I am so despair...so I am trying out everything.
Someone said to place rtrim().
It seems to be working for me now but I need to do more testing if this really fixed it.

I don't  get it though. I checked the both fields from two tables.
They are same length and same data type.

Any idea why would it cause the problem.
0
 
LVL 16

Accepted Solution

by:
GreymanMSC earned 2000 total points
ID: 22772343
Exactly what data type are the fields?  char, varchar, or nvarchar?  It makes a difference.

It sounds as though you are using char, which is a fixed length string.  Thus additional spaces are stored in the field.  But the dropdownlist trims the strings it uses for vales, so the databound string is longer than the supposedly matching value.

Use varchar,
0
 

Author Comment

by:dkim18
ID: 22775682
All my fields are in varchar already.
So that reason doesn't apply to my issue. So I don't understand what's really happening. It is killing me.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question