Solved

Gridview Edit is not working

Posted on 2014-10-26
1
100 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
ID: 40406669
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

911 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

20 Experts available now in Live!

Get 1:1 Help Now