Solved

AppendDataBoundItems Problem

Posted on 2008-10-15
4
303 Views
Last Modified: 2013-12-17
Hi,

I have a DropDownList box configured as shown below. When my DetailsView is in Edit or Insert mode I only want the 4 list items listed below to appear. If I have AppendDataBoundItems set to true I get the list items multiple times from other records in the table (I guess). If I set AppendDataBoundItems to false I only get 1 item in the list (the same as the current record). How can I make it so that the list is always the 4 items only?.

<EditItemTemplate>

OnSelectedIndexChanged="ddlStandardNumber_SelectedIndexChanged" Width="220px" AutoPostBack="True">          
                    <asp:DropDownList ID="ddlStandardNumber" runat="server" AppendDataBoundItems="True"
                        DataSourceID="SqlDataSource1" DataTextField="StandardNumber" DataValueField="StandardNumber"
                        SelectedValue='<%# Bind("StandardNumber") %>' OnSelectedIndexChanged="ddlStandardNumber_SelectedIndexChanged" Width="220px" AutoPostBack="True">
                        <asp:ListItem>BGA-ENG-INST-TS-0001</asp:ListItem>
                        <asp:ListItem>BGA-ENG-INST-TS-0003</asp:ListItem>
                        <asp:ListItem>BGA-ENG-ELEC-TS-0001</asp:ListItem>
                        <asp:ListItem>BGA-ENG-ELEC-TS-0002</asp:ListItem>
                    </asp:DropDownList>
                </EditItemTemplate>

Any help appreciated.

Thanks
Paul.

0
Comment
Question by:pr_wainwright
  • 2
4 Comments
 

Accepted Solution

by:
ghopkins66 earned 63 total points
ID: 22720844
Hello Paul,

I may be missing something here but if you want only the four static ListItems declared in the code above then why do you need to DataBind at all? I think you should get rid of the DataSourceID field.

Regards,
Gareth


0
 
LVL 15

Assisted Solution

by:NazoUK
NazoUK earned 62 total points
ID: 22720869
If you want those 4 static items only, I'm not sure why you are databinding the list at all? Just get rid of the AppendDataBoundItems="True" DataSourceID="SqlDataSource1" DataTextField="StandardNumber" DataValueField="StandardNumber" altogether
0
 
LVL 1

Author Comment

by:pr_wainwright
ID: 22724338
ghopkins66/NazoUK,
                                 I am new to ASP.NET, If I don't databind will the table field be updated with the selected item from the list?. I must be mistaken at what databinding does.

Thanks
Paul.
                                 
0
 

Expert Comment

by:ghopkins66
ID: 22726467
It's the SelectedValue='<%# Bind("StandardNumber") %>' that will link the field to the control. Just try removing the tags that NazoUK has commented.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

813 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now