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>
|