Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 25th, 2007, 04:14 PM
Authorized User
 
Join Date: Jun 2006
Location: , , .
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Default SelectedValue which is invalid--it does not exists

Hello,

I receive the error message, SelectedValue which is invalid because it does not exist in the list of items, because I have nulls in the filed that I would like to update. I have placed the bound drop-down lists to a GridView Control. I have read articles and posts about the issue and have been modifying the field properties, such as, set ConvertEmptyStringToNull=FALSE (Under the Parameter and Bound) but I am not having any success . Any Suggestions will be helpful...

The 3 Drop-down lists are bound to:
<asp:Parameter Name="UnitofIssueID" Type="String" ConvertEmptyStringToNull="False" />
<asp:Parameter Name="automake" Type="String" ConvertEmptyStringToNull="False" />
<asp:Parameter Name="ComponentClassification" Type="String" ConvertEmptyStringToNull="False" />

Exiting WebForm Code
***************************
<%@ Page Language="VB" MasterPageFile="~/DefaultMembers.master" AutoEventWireup="false" CodeFile="subPartUpdate.aspx.vb" Inherits="MemberPages_subPart" title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Main" Runat="Server">
    <h4>
    Part Summary</h4>
    <asp:AccessDataSource ID="PartDataSource" runat="server" DataFile="~/App_Data/Auto.mdb"
        SelectCommand="SELECT * FROM [tblPart]" DeleteCommand="DELETE FROM [tblPart] WHERE [AutoAutoPartID] = ?" InsertCommand="INSERT INTO [tblPart] ([AutoAutoPartID], [UnitofIssueID], [bin], [part_number], [automake], [Auto_Stock], [part_nomenclature], [common_name], [Auto], [unit_price], [ComponentClassification], [SN_Required], [Part_SerialNumber], [RevisionPart], [RevisionDescription], [CN_Required], [ControlNumber], [Remarks], [time_stamp_entry], [time_stamp_update], [time_stamp__delete], [UserName]) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" UpdateCommand="UPDATE [tblPart] SET [UnitofIssueID] = ?, [bin] = ?, [part_number] = ?, [automake] = ?, [Auto_Stock] = ?, [part_nomenclature] = ?, [common_name] = ?, [Auto] = ?, [unit_price] = ?, [ComponentClassification] = ?, [SN_Required] = ?, [Part_SerialNumber] = ?, [RevisionPart] = ?, [RevisionDescription] = ?, [CN_Required] = ?, [ControlNumber] = ?, [Remarks] = ?, [time_stamp_entry] = ?, [time_stamp_update] = ?, [time_stamp__delete] = ?, [UserName] = ? WHERE [AutoAutoPartID] = ?">
        <DeleteParameters>
            <asp:Parameter Name="AutoPartID" Type="Int32" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="UnitofIssueID" Type="String" ConvertEmptyStringToNull="False" />
            <asp:Parameter Name="bin" Type="String" />
            <asp:Parameter Name="part_number" Type="String" />
            <asp:Parameter Name="automake" Type="String" ConvertEmptyStringToNull="False" />
            <asp:Parameter Name="Auto_Stock" Type="String" />
            <asp:Parameter Name="part_nomenclature" Type="String" />
            <asp:Parameter Name="common_name" Type="String" />
            <asp:Parameter Name="AUTO" Type="Double" />
            <asp:Parameter Name="unit_price" Type="Double" />
            <asp:Parameter Name="ComponentClassification" Type="String" ConvertEmptyStringToNull="False" />
            <asp:Parameter Name="SN_Required" Type="Boolean" />
            <asp:Parameter Name="Part_SerialNumber" Type="String" />
            <asp:Parameter Name="RevisionPart" Type="Boolean" />
            <asp:Parameter Name="RevisionDescription" Type="String" />
            <asp:Parameter Name="CN_Required" Type="Boolean" />
            <asp:Parameter Name="ControlNumber" Type="String" />
            <asp:Parameter Name="Remarks" Type="String" />
            <asp:Parameter Name="time_stamp_entry" Type="DateTime" />
            <asp:Parameter Name="time_stamp_update" Type="DateTime" />
            <asp:Parameter Name="time_stamp_delete" Type="DateTime" />
            <asp:Parameter Name="UserName" Type="String" />
            <asp:Parameter Name="AutoPartID" Type="Int32" />
        </UpdateParameters>
        <InsertParameters>
            <asp:Parameter Name="AutoPartID" Type="Int32" />
            <asp:Parameter Name="UnitofIssueID" Type="String" ConvertEmptyStringToNull="False" />
            <asp:Parameter Name="bin" Type="String" />
            <asp:Parameter Name="part_number" Type="String" />
            <asp:Parameter Name="automake" Type="String" ConvertEmptyStringToNull="False" />
            <asp:Parameter Name="Auto_Stock" Type="String" />
            <asp:Parameter Name="part_nomenclature" Type="String" />
            <asp:Parameter Name="common_name" Type="String" />
            <asp:Parameter Name="AUTO" Type="Double" />
            <asp:Parameter Name="unit_price" Type="Double" />
            <asp:Parameter Name="ComponentClassification" Type="String" ConvertEmptyStringToNull="False" />
            <asp:Parameter Name="SN_Required" Type="Boolean" />
            <asp:Parameter Name="Part_SerialNumber" Type="String" />
            <asp:Parameter Name="RevisionPart" Type="Boolean" />
            <asp:Parameter Name="RevisionDescription" Type="String" />
            <asp:Parameter Name="CN_Required" Type="Boolean" />
            <asp:Parameter Name="ControlNumber" Type="String" />
            <asp:Parameter Name="Remarks" Type="String" />
            <asp:Parameter Name="time_stamp_entry" Type="DateTime" />
            <asp:Parameter Name="time_stamp_update" Type="DateTime" />
            <asp:Parameter Name="time_stamp_delete" Type="DateTime" />
            <asp:Parameter Name="UserName" Type="String" />
        </InsertParameters>
    </asp:AccessDataSource>
    <asp:LinkButton ID="FinishButton" runat="server" BorderStyle="Groove" Font-Bold="True"
        OnClientClick="window.opener = null; window.close()">Finished</asp:LinkButton>
    <br />
    <br />
    <asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="False"
        CellPadding="4" DataKeyNames="AutoPartID" DataSourceID="PartDataSource" ForeColor="#333333"
        GridLines="None" AllowPaging="True" PageSize="500">
        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <Columns>
            <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
            <asp:BoundField DataField="AutoPartID" HeaderText="ID" InsertVisible="False" ReadOnly="True"
                SortExpression="AutoPartID" />
            <asp:BoundField DataField="part_number" HeaderText="Part Number" SortExpression="part_number" />
            <asp:BoundField DataField="common_name" HeaderText="Common Name" SortExpression="common_name" />
            <asp:BoundField DataField="part_nomenclature" HeaderText="Supply Center Part Nomen"
                SortExpression="part_nomenclature" />
            <asp:BoundField DataField="bin" HeaderText="BIN" SortExpression="bin" />
            <asp:TemplateField ConvertEmptyStringToNull="False" HeaderText="Automake" SortExpression="automake">
                <EditItemTemplate>
                    <asp:DropDownList ID="AutomakeDDL" runat="server" DataSourceID="automakeDDLDataSource"
                        DataTextField="Automake" DataValueField="Automake" SelectedValue='<%# Bind("automake") %>' AppendDataBoundItems="True">
                    </asp:DropDownList>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("automake") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="Auto_Stock" HeaderText="Federal Stock #" SortExpression="Auto_Stock" />
            <asp:BoundField DataField="unit_price" HeaderText="Unit Price" SortExpression="unit_price" />
            <asp:BoundField DataField="AUTO" HeaderText="AUTO" SortExpression="AUTO" />
            <asp:TemplateField ConvertEmptyStringToNull="False" HeaderText="Unit of Issue" SortExpression="UnitofIssueID">
                <EditItemTemplate>
                    <asp:DropDownList ID="UOIDDL" runat="server" DataSourceID="UOIDDLDataSource"
                        DataTextField="UnitofIssueID" DataValueField="UnitofIssueID" SelectedValue='<%# Bind("UnitofIssueID") %>' AppendDataBoundItems="True">
                    </asp:DropDownList>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label2" runat="server" Text='<%# Bind("UnitofIssueID") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField ConvertEmptyStringToNull="False" HeaderText="Classification" SortExpression="ComponentClassification">
                <EditItemTemplate>
                    <asp:DropDownList ID="ClassifyDDL" runat="server" DataSourceID="ClassifyDS"
                        DataTextField="ComponentClassificationID" DataValueField="ComponentClassificationID"
                        SelectedValue='<%# Bind("ComponentClassification") %>' AppendDataBoundItems="True">
                    </asp:DropDownList>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label3" runat="server" Text='<%# Bind("ComponentClassification") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:CheckBoxField DataField="SN_Required" HeaderText="Does This Part Have A Serial Number?"
                SortExpression="SN_Required" />
            <asp:BoundField DataField="Part_SerialNumber" HeaderText="Serial Number" SortExpression="Part_SerialNumber" />
            <asp:CheckBoxField DataField="RevisionPart" HeaderText="Is This A Revision Part?"
                SortExpression="RevisionPart" />
            <asp:BoundField DataField="RevisionDescription" HeaderText="Revision Description"
                SortExpression="RevisionDescription" />
            <asp:CheckBoxField DataField="CN_Required" HeaderText="Does This Part Have A Control Number?"
                SortExpression="CN_Required" />
            <asp:BoundField DataField="ControlNumber" HeaderText="Control Number" SortExpression="ControlNumber" />
            <asp:BoundField DataField="Remarks" HeaderText="Remarks" SortExpression="Remarks" />
            <asp:BoundField DataField="time_stamp_entry" HeaderText="Record Created" SortExpression="time_stamp_entry" />
            <asp:BoundField DataField="time_stamp_update" HeaderText="Record Last Updated" SortExpression="time_stamp_update" />
            <asp:BoundField DataField="time_stamp__delete" HeaderText="Record Deleted" SortExpression="time_stamp__delete" />
            <asp:BoundField DataField="UserName" HeaderText="Record Modified By" SortExpression="UserName" />
        </Columns>
        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
        <EditRowStyle BackColor="#999999" />
        <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
    </asp:GridView>
    <br />
    <br />
    <br />
    <asp:AccessDataSource ID="automakeDDLDataSource" runat="server" DataFile="~/App_Data/Auto.mdb"
        SelectCommand="SELECT DISTINCT [automake] FROM [tblAutomakeRef]" CancelSelectOnNullParameter="False"></asp:AccessDataSource>
    <br />
    <asp:AccessDataSource ID="UOIDDLDataSource" runat="server" DataFile="~/App_Data/Auto.mdb"
        SelectCommand="SELECT DISTINCT [UnitofIssueID] FROM [tblUnitofMeasure]" CancelSelectOnNullParameter="False"></asp:AccessDataSource>
    <br />
    <asp:AccessDataSource ID="ClassifyDS" runat="server" CacheExpirationPolicy="Sliding"
        DataFile="~/App_Data/Auto.mdb" SelectCommand="SELECT DISTINCT [ComponentClassification] FROM [tblClassification]" CancelSelectOnNullParameter="False">
    </asp:AccessDataSource>
    <br />
    <br />
    <br />
</asp:Content>

Reply With Quote
  #2 (permalink)  
Old October 26th, 2007, 08:01 AM
Authorized User
 
Join Date: Jun 2006
Location: , , .
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I fixed the null problem by adding a static entry "" into the drop down list, but when I click edit to update the record and make my change to a field and click update the data stays the same. An Ideas, thank you.


Solution to question-- Static Entry
<EditItemTemplate>

<asp:SqlDataSource ID="DSKonf" runat="server" ConnectionString="<%$ ConnectionStrings:EventsConnectionString %>"

SelectCommand="SELECT * FROM [AktuelleKonfSteuerung]"></asp:SqlDataSource>


</EditItemTemplate>


<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="DSPLZ" DataTextField="PLZ"

DataValueField="PLZ" SelectedValue='<%# Bind("adressplz") %>'>

</asp:DropDownList> ..

The problems come if the data in the table doesnt fit your data in the PLZ table. Most common reason is that the field contains a NULL Value. Bind fails!

The trick is that you can add items to the dropdown list by declaration. The second part of the trick is to add the DB entrys to the declarated entrys by AppenddataboundItems. Take care to set the value to "" cause the bind gives also back a "" if the field contains NULL

<asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="DSPLZ" DataTextField="PLZ"

DataValueField="PLZ" SelectedValue='<%# Bind("shipPLZ") %>' AppendDataBoundItems=true>

<asp:ListItem Text="wählen" Value=""></asp:ListItem>

</asp:DropDownList>



</asp:TemplateField>

Reply With Quote
  #3 (permalink)  
Old October 26th, 2007, 10:29 AM
Authorized User
 
Join Date: Jun 2006
Location: , , .
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I fixed the update problem thank you,

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Get SelectedValue of Control obrienkev C# 2005 3 November 8th, 2007 12:17 PM
Need Help with DropDownList SelectedValue putputty ASP.NET 2.0 Basics 4 June 27th, 2007 11:44 AM
DropDownList.SelectedValue weirdness Aaron Edwards ASP.NET 2.0 Basics 5 March 7th, 2007 12:39 AM
comboBox.SelectedValue melvik C# 1 August 19th, 2003 09:21 AM



All times are GMT -4. The time now is 07:45 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.