Solved

selectedValue property in dropdownlist of detailsview??

Posted on 2008-10-20
8
594 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
  • 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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

777 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