Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 763
  • Last Modified:

DropDownList in FormView with no list in EditItemTemplate

DropDownList in EditItemTemplate of a FormView contains only the value in the record.

How can I get the four different options to show in the DropDownList so that I can change the value when in Edit mode of the FormView?

The DropDownList shows the correct value from the selected record, but only that one value is in the dropdown.  I want to be able to select another value and change the record. I can change other fields which are mostly TextBoxes and CheckBoxes just fine.

What am I missing?  Thanks.
<asp:DropDownList ID="ddlGoal" runat="server" Width="250px" 
							DataValueField="SuggestionID"
							DataSourceID="SqlDataSource2"
							DataTextField="Goal">
				        <asp:ListItem Value="1" Text="Goal 1 - Increase Sustainability of Workforce System"></asp:ListItem>
						<asp:ListItem Value="2" Text="Goal 2 - Maintain Role as Local Workforce Leaders"></asp:ListItem>
				        <asp:ListItem Value="3" Text="Goal 3 - Customers Choose One-Stops as 1st Choice"></asp:ListItem>
				        <asp:ListItem Value="4" Text="Goal 4 - Maximize Employment & Training to Targeted Groups"></asp:ListItem>
					</asp:DropDownList>

Open in new window

0
megnin
Asked:
megnin
  • 9
  • 5
1 Solution
 
Praveen VenuCommented:
put the codes that bind the ddlGoal outside the IspostBack check
0
 
megninAuthor Commented:
IspostBack check?

On the .aspx page I have a SqlDataSource2.
The code in the Code Snippet above is in the EditItemTemplate of the FormView.  That's where I'm binding the ddlGoal.

Unless I missunderstood your comment, I don't have an IspostBack check.
0
 
megninAuthor Commented:
I added a ListItem with a Value="0" and added AppendDataBoundItems="True" and SelectedValue='<%# Bind("Goal") %>'

The DropDownList works but I get an extra instance of whatever the current item is at the bottom of the list.  For example if the record currently contains "Goal 2 -", when I go to edit it I get a dropdown populated thus:
-Select-
Goal 1 -
Goal 2 -
Goal 3 -
Goal 4 -
Goal 2 -

It appears that "AppendDataBoundItems="True" is doing exactly that, but if I set it to False, then I get this error:
'ddlGoal' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value

Do I just have to live with that extra item or is there a way to fix it?
<asp:DropDownList ID="ddlGoal" runat="server" Width="250px" 
		DataSourceID="SqlDataSource2"
		DataTextField="Goal"
		DataValueField="SuggestionID"
		Enabled="True"
		SelectedValue='<%# Bind("Goal") %>' 
		AppendDataBoundItems="True">
	<asp:ListItem Text="-Select-" Value="0"></asp:ListItem>
    <asp:ListItem Value="Goal 1 - Increase Sustainability of Workforce System" Text="Goal 1 - Increase Sustainability of Workforce System"></asp:ListItem>
	<asp:ListItem Value="Goal 2 - Maintain Role as Local Workforce Leaders" Text="Goal 2 - Maintain Role as Local Workforce Leaders"></asp:ListItem>
    <asp:ListItem Value="Goal 3 - Customers Choose One-Stops as 1st Choice" Text="Goal 3 - Customers Choose One-Stops as 1st Choice"></asp:ListItem>
    <asp:ListItem Value="Goal 4 - Maximize Employment & Training to Targeted Groups" Text="Goal 4 - Maximize Employment & Training to Targeted Groups"></asp:ListItem>
</asp:DropDownList>

Open in new window

0
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
megninAuthor Commented:
Dear Admin,
I haven't abandoned this question, I just haven't gotten a response from the "Expert".
0
 
Praveen VenuCommented:
Can you please explain the requirement little more clearly?
0
 
megninAuthor Commented:
Hi, yes the problem is this:
With a DropDownList containing 4 items, configured as in the Code Snippet above...
The DropDownList works but I get an extra instance of whatever the current item is at the bottom of the list.  For example if the record currently contains "Goal 2 -", when I go to edit it I get a dropdown populated thus:
-Select-
Goal 1 -
Goal 2 -
Goal 3 -
Goal 4 -
Goal 2 -

What I need is for the DropDownList to only show the 4 items:
Goal 1 -
Goal 2 -
Goal 3 -
Goal 4 -

It is showing an extra item at the botton of the list which is whatever the value of that field currently in the database.   This is in an EditItemTemplate, so I'm changing an existing record with an existing value.  That existing value is being Appended to the list of items in the DropDownList.

See my comment, "ID:23606539Author:megninDate:02.10.2009 at 06:00PM EST".

Thanks.
0
 
megninAuthor Commented:
Okay, here's a new RadioButtonList I'm working with that has the same problem.

This one is also inside the EditItemTemplate of a FormView:

                        <asp:RadioButtonList ID="radStatus" runat="server" RepeatDirection="Vertical"
                                                 RepeatLayout="Flow"
                                                 DataSourceID="SqlDataSource1"
                                                 DataTextField="Status"
                                                 DataValueField="keyApplicantID"
                                                 SelectedValue='<%# Bind("Status") %>'
                                                 AppendDataBoundItems="True"
                                                 >
                          <asp:ListItem Value="0">None</asp:ListItem>
                          <asp:ListItem Value="1">Complete</asp:ListItem>
                          <asp:ListItem Value="2">Pending</asp:ListItem>
                          <asp:ListItem Value="3">Ineligable</asp:ListItem>
                    </asp:RadioButtonList>

It doesn't work at all and I get an error if I don't have "AppendDataBoundItems='True' "
With it, instead of the four items above that I want radio buttons for, there are 5.  One extra one at the bottom always has whatever value is currently in the database (for the field this radiobutton is for).  I'd really like to get rid of that extra item.
0
 
megninAuthor Commented:
Here is what it looks like.  Since the Current value is "1" there's that extra radio button on the bottom labeled "1"
RadioButtonList.jpg
0
 
Praveen VenuCommented:
try this

 <asp:RadioButtonList ID="radStatus" runat="server" RepeatDirection="Vertical"
                                                 RepeatLayout="Flow"
                                                 DataSourceID="SqlDataSource1"
 
                                                 SelectedValue='<%# Bind("Status") %>'
                                                 AppendDataBoundItems="True"
                                                 >
                          <asp:ListItem Value="0">None</asp:ListItem>
                          <asp:ListItem Value="1">Complete</asp:ListItem>
                          <asp:ListItem Value="2">Pending</asp:ListItem>
                          <asp:ListItem Value="3">Ineligable</asp:ListItem>
                    </asp:RadioButtonList>

Open in new window

0
 
megninAuthor Commented:
I think I need that line to tell it where to get the data.
RadioButtonList2.jpg
RadioButtonList3.jpg
0
 
Praveen VenuCommented:
Are you sure that the value of

<%# Bind("Status") %> is 0,1,2 or 3
0
 
megninAuthor Commented:
Well right now it's all 0 except for one test record that is currently 3 and so the EditItemTemplate in the web browser looks like this:

RadioButtonList4.jpg
0
 
Praveen VenuCommented:
Please post the answer and mark the solution
0
 
megninAuthor Commented:
In this comment:
ID:23606539Author:megninDate:02.10.2009 at 06:00PM EST

What I added was not suggested by anyone else, I found it "Googling".  
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

  • 9
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now