Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
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
 
Old October 2nd, 2007, 08:08 AM
Registered User
 
Join Date: Oct 2007
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default DropDownList not submitting to db

I think I'm missing something really obvious but can't for the life of me figure out what. I've got a details view submitting to a db but for some reason the dropdown list field isn't going through the update even though (I think) I've specified that it should and it is throwing the error that it can't submit because the column can't be null. Here is the code of what I've done. Am I missing something really obvious???

<form id="form1" runat="server">
    <div>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:PublicationsListConnectionString %>"
            SelectCommand="SELECT Status.Status, PublicationRecords.NameOrTitle, PublicationRecords.LocationOfDocument, PublicationRecords.Description, PublicationRecords.ISBN_ISSN_DOI FROM Status INNER JOIN PublicationRecords ON Status.StatusID = PublicationRecords.StatusID WHERE (PublicationRecords.ID = @ID)"
            UpdateCommand="UPDATE PublicationRecords SET StatusID = @StatusID, NameOrTitle = @NameOrTitle, LocationOfDocument = @LocationOfDocument, Description = @Description, ISBN_ISSN_DOI = @ISNB_ISSN_DOI">
            <SelectParameters>
                <asp:QueryStringParameter Name="ID" QueryStringField="ID" />
            </SelectParameters>
            <UpdateParameters>
                <asp:Parameter Name="StatusID" Type="Int32" />
                <asp:Parameter Name="NameOrTitle" Type="String" />
                <asp:Parameter Name="LocationOfDocument" Type="String" />
                <asp:Parameter Name="Description" Type="String" />
                <asp:Parameter Name="ISNB_ISSN_DOI" />
                </UpdateParameters>
        </asp:SqlDataSource>
        &nbsp;&nbsp;<asp:SqlDataSource ID="StatusSqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:PublicationsListConnectionString %>"
            SelectCommand="SELECT * FROM [Status]">
        </asp:SqlDataSource>

        <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataSourceID="SqlDataSource1"
            Height="50px" Width="125px">
            <Fields>
                    <asp:TemplateField>
                    <ItemTemplate>
                            <asp:Label ID="StatusLabel" runat="server" Text='<%# Bind("Status") %>'></asp:Label>
                        </ItemTemplate>
                <EditItemTemplate>
                    <asp:DropDownList ID="StatusID" runat="server" DataSourceID="StatusSqlDataSource"
                        DataTextField="Status" DataValueField="StatusID" AutoPostBack="True">
                    </asp:DropDownList>
                </EditItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="NameOrTitle" HeaderText="NameOrTitle" SortExpression="NameOrTitle" />
                <asp:BoundField DataField="LocationOfDocument" HeaderText="LocationOfDocument" SortExpression="LocationOfDocument" />
                <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
                <asp:BoundField DataField="ISBN_ISSN_DOI" HeaderText="ISBN_ISSN_DOI" SortExpression="ISBN_ISSN_DOI" />
                <asp:CommandField ShowEditButton="True" />
            </Fields>
        </asp:DetailsView>
    </div>
    </form>

 
Old October 2nd, 2007, 10:03 AM
Authorized User
 
Join Date: Aug 2007
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Add

SelectedValue='<%# Bind("StatusID") %>'

to your dropdownlist in the EditItemTemplate. This statement will bind the selected value to the StatusId parameter. I just worked this one out today :P
 
Old October 2nd, 2007, 10:36 AM
Registered User
 
Join Date: Oct 2007
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks, I've added that and its working however now it updates both records in the db rather than the specified one.

I've tried adding Where ID=@ID to the update statement however when I do it doesn't seem to update the db. When you press update the details view reverts back to the previous view with the original data.

 
Old October 2nd, 2007, 10:50 AM
Authorized User
 
Join Date: Aug 2007
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It may have updated the data, refresh the page and see if the value changes.

If not, then i'll try figure it out and get back to you.

 
Old October 3rd, 2007, 03:35 AM
Registered User
 
Join Date: Oct 2007
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Nope tried hitting refresh and checked the dummy data in the db and it hasn't updated. I'm wondering if I have to do something with the onitemupdating command?

 
Old October 3rd, 2007, 03:56 AM
Registered User
 
Join Date: Oct 2007
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Woo hoo I've got it working. I added DataKeyNames="ID" into the detaisl view and its updating the specified record :D


 
Old October 3rd, 2007, 05:48 AM
Authorized User
 
Join Date: Aug 2007
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Woo! Glad you got it working! :D






Similar Threads
Thread Thread Starter Forum Replies Last Post
DropDownList value insert to MS DB(DetailsView) yukijocelyn ASP.NET 2.0 Basics 2 August 23rd, 2007 01:32 AM
Submitting multiple selection to mysql DB preston2003 BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 1 May 11th, 2005 11:06 PM
form submitting cro_crx Pro PHP 5 January 25th, 2005 12:19 PM
Form Submitting cro_crx Beginning PHP 3 January 17th, 2005 01:30 PM





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