Solved

Gridview Edit is not working

Posted on 2014-10-26
1
94 Views
Last Modified: 2014-10-28
I have a gridview and when I click the update button nothing is happening.  I do not get an error.  I'm sure it is something simple, but I am missing it.


<asp:GridView ID="gvLocations" runat="server" AllowPaging="True" 
    AllowSorting="True" AutoGenerateColumns="False" CellPadding="3" 
    DataSourceID="dsLocations" ForeColor="Black" GridLines="Vertical" 
        BackColor="White" BorderColor="#999999" BorderStyle="Solid" 
        BorderWidth="1px" AutoGenerateEditButton="True">
        <Columns>
            <asp:BoundField DataField="Location_Name" HeaderText="Location" 
                SortExpression="Location_Name" />
            <asp:BoundField DataField="Address1" HeaderText="Address1" 
                SortExpression="Address1" />
            <asp:BoundField DataField="Address2" HeaderText="Address2" 
                SortExpression="Address2" />
            <asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
            <asp:BoundField DataField="StateAbbr" HeaderText="State" 
                SortExpression="StateAbbr" />
            <asp:BoundField DataField="Zip" HeaderText="Zip" SortExpression="Zip" />
            <asp:BoundField DataField="column1" HeaderText="Co-Op" 
                SortExpression="column1" />
            <asp:TemplateField HeaderText="Store Type " SortExpression="StoreTypeName">
                <EditItemTemplate>
                    <asp:DropDownList ID="DropDownList1" runat="server" AppendDataBoundItems="True" 
                        DataSourceID="dsStoreType" DataTextField="StoreTypeName" 
                        DataValueField="StoreTypeID" SelectedValue='<%# Bind("StoreTypeID") %>'>
                        <asp:ListItem Selected="True" Value="">Select</asp:ListItem>
                    </asp:DropDownList>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("StoreTypeName") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>

    <asp:SqlDataSource ID="dsLocations" runat="server" 
        ConnectionString="<%$ ConnectionStrings:POSDataString %>" 
        
        SelectCommand="SELECT Locations.[Location Name] AS Location_Name, Locations.Address1, Locations.Address2, Locations.City, Locations.StateAbbr, Locations.Zip, Locations.[Co-Op] AS column1, Locations.StoreTypeID, StoreType.StoreTypeName FROM Locations LEFT OUTER JOIN StoreType ON Locations.StoreTypeID = StoreType.StoreTypeID" 
        
        UpdateCommand="UPDATE Locations SET Address1 = @Address1, Address2 = @Address2, City = @City, StateAbbr = @StateAbbr, Zip = @Zip, [Co-Op] = '[@Co-Op]', StoreTypeID = @StoreTypeId WHERE ([Location Name] = @LocationName)">
        <UpdateParameters>
            <asp:Parameter Name="Address1"/>
            <asp:Parameter Name="Address2"/>
            <asp:Parameter Name="City" Type="String"/>
            <asp:Parameter Name="StateAbbr" Type="String"/>
            <asp:Parameter Name="Zip" Type="String" />
            <asp:Parameter Name="StoreTypeId" Type="Int32" />
            <asp:Parameter Name="LocationName"/>
        </UpdateParameters>
    </asp:SqlDataSource>

Open in new window

0
Comment
Question by:rcowen00
1 Comment
 
LVL 28

Accepted Solution

by:
sammySeltzer earned 500 total points
Comment Utility
The very first thing I noticed is this:

'[@Co-Op]'

[Co-Op] = '[@Co-Op]'

Why????

Second, I don't see it declared in <Update Parameters>

I would try something like this:

[Co-Op] = @Co_Op

Then in update paramerts section I would have:

            <asp:Parameter Name="Co_Op" Type="String"/>
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

772 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

11 Experts available now in Live!

Get 1:1 Help Now