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 March 20th, 2008, 09:18 AM
Registered User
 
Join Date: Mar 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem with gridview update.

Ok, I have a simple page that searches an access database by first and last name. I am setting the gridview to update after the record has been found. For some reason it will update everything but the first and last name, if I try to update first and last name it actually deletes the record.

Here is my code:



 <form id="form1" runat="server">
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="AccessDataSource1"
        BackColor="LightGoldenrodYellow" BorderColor="Tan" BorderWidth="1px"
        CellPadding="5" ForeColor="Black" GridLines="None" DataKeyNames="ID">
        <FooterStyle BackColor="Tan" />
        <Columns>
        <asp:TemplateField><ItemTemplate>
            <asp:LinkButton ID="LinkButton1" Runat="server"
           OnClientClick="return confirm('Are you sure you want to delete this record?');"
                CommandName="Delete">Delete</asp:LinkButton>
        </ItemTemplate>
        </asp:TemplateField>
            <asp:CommandField ShowEditButton="True" />
            <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False"
                  SortExpression="ID" ReadOnly="True" Visible="False" />
            <asp:BoundField DataField="First_Name" HeaderText="First Name"
                SortExpression="First_Name" />
            <asp:BoundField DataField="Last_Name" HeaderText="Last Name"
                SortExpression="Last_Name" />
            <asp:BoundField DataField="Date_of_Birth" HeaderText="Date of Birth"
                SortExpression="Date_of_Birth" DataFormatString="{0:d}" />
            <asp:BoundField DataField="Address" HeaderText="Address"
                SortExpression="Address" />
            <asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
            <asp:BoundField DataField="State" HeaderText="State" SortExpression="State" />
            <asp:BoundField DataField="Zip_Code" HeaderText="Zip Code"
                SortExpression="Zip_Code" />
            <asp:BoundField DataField="PlayerTypeID" HeaderText="PlayerTypeID"
                SortExpression="PlayerTypeID" Visible="False" />

                <asp:TemplateField HeaderText="Employee Type">
         <ItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server"
        DataSourceID="AccessDataSource2" DataTextField="PlayerType" DataValueField="ID"
        SelectedValue='<%#Bind("PlayerTypeID") %>'>


</asp:DropDownList>

            </ItemTemplate>



<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server"
        DataSourceID="AccessDataSource2" DataTextField="PlayerType" DataValueField="ID"
        SelectedValue='<%#Bind("PlayerTypeID") %>'>


</asp:DropDownList>

            </EditItemTemplate>



</asp:TemplateField>

        </Columns>
        <PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue"
            HorizontalAlign="Center" />
        <SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
        <HeaderStyle BackColor="Tan" Font-Bold="True" />
        <AlternatingRowStyle BackColor="PaleGoldenrod" />
    </asp:GridView>
    <asp:AccessDataSource ID="AccessDataSource1" runat="server"
        DataFile="~/App_Data/ineligible_players.mdb"
        DeleteCommand="DELETE FROM Player where ID = ?"
        SelectCommand="SELECT Player.ID, Player.First_Name, Player.Last_Name, Player.Date_of_Birth, Player.Address, Player.City, Player.State, Player.Zip_Code, Player.PlayerTypeID FROM (Player INNER JOIN PlayerType ON Player.PlayerTypeID = PlayerType.ID) WHERE (Player.First_Name = ?) AND (Player.Last_Name = ?)
"

        UpdateCommand="UPDATE [Player]

SET player.First_Name = ?, player.Last_Name = ?, player.Date_of_Birth = ?, player.Address = ?, player.City= ?, player.State = ?, player.Zip_Code = ?, player.PlayerTypeID = ?


WHERE player.id = ?">
        <SelectParameters>
            <asp:ControlParameter ControlID="TextBox1" Name="First_Name" PropertyName="Text" />
            <asp:ControlParameter ControlID="TextBox2" Name="Last_Name" PropertyName="Text" />
        </SelectParameters>
    </asp:AccessDataSource>
    <asp:AccessDataSource ID="AccessDataSource2" runat="server"
        DataFile="~/App_Data/ineligible_players.mdb"
        SelectCommand="SELECT [id], [PlayerType] FROM [PlayerType]">
    </asp:AccessDataSource>
    <br />
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    <br />
    <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
    <br />
    <asp:Button ID="Button1" runat="server" Text="Button" />
    <br />
    <br />
    <br />
    <br />
    </form>






Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't get GridView to update xr280xr ASP.NET 2.0 Professional 5 February 15th, 2008 12:45 PM
using gridview control, how to update? aaronabdiel ASP.NET 2.0 Basics 2 February 13th, 2008 08:41 AM
Gridview using Update *only* pbranumfl ASP.NET 2.0 Basics 2 December 4th, 2006 03:21 PM
Gridview Update Issue jpgregg ASP.NET 2.0 Professional 0 September 1st, 2006 07:35 PM
FOXPRO gridview update webclown ASP.NET 1.x and 2.0 Application Design 0 May 1st, 2006 12:43 PM





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