Edit Gridview Bound to dataset??

Trying to use the AutGenerate Edit feature in VS05.
It appears on the grid, but when I EDIT a column and press UPDATE it just returns to the state it was in.
The Delete works, but not Edit/Update.

CODE:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="AddGoal.aspx.vb" Inherits="AddGoal" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        &nbsp;</div>
        <asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="False"
            AutoGenerateDeleteButton="True" AutoGenerateEditButton="True" BackColor="White"
            BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3" DataSourceID="SqlDataSource1"
            GridLines="Vertical" HorizontalAlign="Center">
            <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
            <Columns>
                <asp:BoundField DataField="CurrentMonth" HeaderText="CurrentMonth" SortExpression="CurrentMonth" />
                <asp:BoundField DataField="StoreNum" HeaderText="StoreNum" SortExpression="StoreNum" />
                <asp:BoundField DataField="StoreName" HeaderText="StoreName" SortExpression="StoreName" />
                <asp:BoundField DataField="SalesGoal" HeaderText="SalesGoal" SortExpression="SalesGoal" DataFormatString="{0:F2}" HtmlEncode="False" />
                <asp:BoundField DataField="EFTGoal" HeaderText="EFTGoal" SortExpression="EFTGoal" DataFormatString="{0:F2}" HtmlEncode="False" />
            </Columns>
            <RowStyle BackColor="#EEEEEE" Font-Names="Tahoma" Font-Size="Smaller" ForeColor="Black"
                Wrap="False" />
            <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
            <HeaderStyle BackColor="#000084" Font-Bold="True" Font-Names="Tahoma" Font-Size="Small"
                ForeColor="White" Wrap="False" />
            <AlternatingRowStyle BackColor="Gainsboro" />
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:CorpWebConnectionString %>"
            SelectCommand="SELECT * FROM [NumbersGoals]" DeleteCommand="DELETE FROM [NumbersGoals] WHERE [CurrentMonth] = @original_CurrentMonth AND [StoreNum] = @original_StoreNum" InsertCommand="INSERT INTO [NumbersGoals] ([CurrentMonth], [StoreNum], [StoreName], [SalesGoal], [EFTGoal]) VALUES (@CurrentMonth, @StoreNum, @StoreName, @SalesGoal, @EFTGoal)" OldValuesParameterFormatString="original_{0}" UpdateCommand="UPDATE [NumbersGoals] SET [StoreName] = @StoreName, [SalesGoal] = @SalesGoal, [EFTGoal] = @EFTGoal WHERE [CurrentMonth] = @original_CurrentMonth AND [StoreNum] = @original_StoreNum">
            <DeleteParameters>
                <asp:Parameter Name="original_CurrentMonth" Type="String" />
                <asp:Parameter Name="original_StoreNum" Type="String" />
            </DeleteParameters>
            <UpdateParameters>
                <asp:Parameter Name="StoreName" Type="String" />
                <asp:Parameter Name="SalesGoal" Type="Decimal" />
                <asp:Parameter Name="EFTGoal" Type="Decimal" />
                <asp:Parameter Name="original_CurrentMonth" Type="String" />
                <asp:Parameter Name="original_StoreNum" Type="String" />
            </UpdateParameters>
            <InsertParameters>
                <asp:Parameter Name="CurrentMonth" Type="String" />
                <asp:Parameter Name="StoreNum" Type="String" />
                <asp:Parameter Name="StoreName" Type="String" />
                <asp:Parameter Name="SalesGoal" Type="Decimal" />
                <asp:Parameter Name="EFTGoal" Type="Decimal" />
            </InsertParameters>
        </asp:SqlDataSource>
    </form>
</body>
</html>

TIA,
Andrew
AhelblingAsked:
Who is Participating?
 
madhevan_pillaiConnect With a Mentor Commented:
Hi,

 You have not set DataKeyNames attribute of the grid. DataKeyNames  is the primary key field
0
 
madhevan_pillaiCommented:
Hi

see the sample below where Id is the primary key

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="EditDeleteGrid.aspx.vb" Inherits="Database_EditDeleteGrid" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" AutoGenerateDeleteButton="True"
            AutoGenerateEditButton="True" AutoGenerateSelectButton="True" DataKeyNames="Id" DataSourceID="SqlDataSource1" >
            <Columns>
           <asp:BoundField DataField="Id" />
                <asp:BoundField DataField="Name" />
                <asp:BoundField DataField="Age" />
            </Columns>
        </asp:GridView>
   
    </div>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TestConnectionString3 %>"
            SelectCommand="SELECT * FROM [Table3]" UpdateCommand="UPDATE Table3 SET Name =@Name, Age =@Age WHERE Id=@Id" InsertCommand="INSERT INTO Table3(Name, Age) VALUES (@Name,@Age)" DeleteCommand="DELETE FROM Table3 WHERE (Id = @Id)">
           
        </asp:SqlDataSource>
    </form></body>
</html>
0
 
AhelblingAuthor Commented:
i have multiple keys - CurrentMonth AND StoreNum
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
AhelblingAuthor Commented:
ok I added both as DatakeyNames... it will let me edit all fields except the two I added as DataKeyNames?  How can I Edit those as well?
0
 
AhelblingAuthor Commented:
nevermind - I dont need to change the keyed fields....How can I have EDIT and DELETE in 2 seperate columns instead of both of them in one as they are now??
0
 
madhevan_pillaiCommented:
In that case use a autogenerated column.
0
 
AhelblingAuthor Commented:
I set that to True and it doubled up the current columns and left EDIT and DELETE in 1 column??

        <asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="True"
            AutoGenerateDeleteButton="True" AutoGenerateEditButton="True" BackColor="White"
            BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3" DataSourceID="SqlDataSource1"
            GridLines="Vertical" HorizontalAlign="Center" DataKeyNames="CurrentMonth,StoreNum">
0
 
madhevan_pillaiCommented:
what i said is a unique single column from the database. Autoseed column from the database.if so u can edit CurrentMonth,StoreNum
0
 
madhevan_pillaiCommented:
<asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="False"
            AutoGenerateDeleteButton="True" AutoGenerateEditButton="True" BackColor="White"
            BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3" DataSourceID="SqlDataSource1"
            GridLines="Vertical" HorizontalAlign="Center" DataKeyNames="Id"> where Id is a unique column from th database
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.