Solved

AppendDataBoundItems Problem

Posted on 2008-10-15
4
298 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

705 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

18 Experts available now in Live!

Get 1:1 Help Now