Gridview not updating data

A

Avanti

Hello,

I have a gridview wherein I've added functionality for Edit. Now, when
I click on the Edit button, and modify a field, and click on the Update
button, the new values disappear and the old values are retained.

Here is my source code:
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!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" DataKeyNames="OrderID"
DataSourceID="SqlDataSource1" AllowPaging="True"
AllowSorting="True" OnRowDataBound="GridView1_RowDataBound"
OnRowUpdated="GridView1_RowUpdated"
OnRowUpdating="GridView1_RowUpdating">
<Columns>
<asp:CommandField ShowSelectButton="True"
ShowEditButton="True" />
<asp:BoundField DataField="OrderID"
HeaderText="OrderID" InsertVisible="False" ReadOnly="True"
SortExpression="OrderID" />
<asp:BoundField DataField="CustomerID"
HeaderText="CustomerID" SortExpression="CustomerID" />
<asp:BoundField DataField="OrderDate"
HeaderText="OrderDate" SortExpression="OrderDate" />
<asp:BoundField DataField="ShipCity"
HeaderText="ShipCity" SortExpression="ShipCity" />
<asp:TemplateField HeaderText="EmployeeID"
SortExpression="EmployeeID">
<ItemTemplate>
<asp:GridView ID="GridView2" runat="server"
AutoGenerateColumns="False"
DataKeyNames="EmployeeID" DataSourceID="SqlDataSource2">
<Columns>
<asp:CommandField ShowSelectButton="True"
ShowEditButton="True" />
<asp:BoundField DataField ="EmployeeID" />
<asp:BoundField DataField="LastName" />
<asp:BoundField DataField ="FirstName" />
<asp:BoundField DataField ="Title" />
<asp:TemplateField HeaderText="City">
<EditItemTemplate>
<asp:TextBox ID="TextBox1"
runat="server"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1"
runat="server" Text='<%# Bind("City") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>



</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource2"
runat="server" ConnectionString="<%$
ConnectionStrings:NorthwindConnectionString %>" SelectCommand='<%#
Eval("EmployeeID", "Select EmployeeID, LastName, FirstName, Title, City
from Employees where EmployeeID={0}")%>' UpdateCommand = '<%#
Eval("EmployeeId" , "update employees set
firstname=@firstname,lastname=@lastname,title=@title,city=@city where
employeeid={0}")%>'></asp:SqlDataSource>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1"
OldValuesParameterFormatString="original_{0}"
runat="server" ConnectionString="<%$
ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="select * from orders" UpdateCommand="update
orders set
customerid=@customerid,orderdate=@orderdate,shipcity=@shipcity where
employeeid=@employeeid">
<UpdateParameters>
<asp:parameter Name="customerid" />
<asp:parameter Name="orderdate" />
<asp:parameter Name="shipcity" />
<asp:parameter Name="employeeid" />
<asp:parameter Name="orderid" />
</UpdateParameters>
</asp:SqlDataSource>

</div>
</form>
</body>
</html>

Any help is greatly appreciated.
Thanks in advance
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top