Solved

selectedValue property in dropdownlist of detailsview??

Posted on 2008-10-20
8
600 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 500 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

Industry Leaders: 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!

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

735 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