473,405 Members | 2,176 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Gridview not updating data

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=@tit le,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,shipci ty=@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

Feb 22 '06 #1
1 1785
Jon
Is it going into the Database? If it is, you may have to do a rebind?

"Avanti" wrote:
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=@tit le,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,shipci ty=@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

Feb 23 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: P | last post by:
Hello, I am having a difficult time updating a record via a stored procedure using the gridview and sqldatasource. I cannot seem to be able to find a way to set everything up so that I can pass...
3
by: | last post by:
Hello, I have created an ASP.NET 2.0 application that utilized a Gridview Control to display and update/delete data. The problem I am having is that the gridview control is displaying the data...
8
by: Mike Kelly | last post by:
I've chosen to implement the "optimistic concurrency" model in my application. To assist in that, I've added a ROWVERSION (TIMESTAMP) column to my main tables. I read the value of the column in my...
4
by: Nalaka | last post by:
Hi, I have two questions about gridViews. 1. How can I intercept the row/column values at loading to change values? 2. After I update a row (using default update functionality), how can I...
4
by: Jim Katz | last post by:
I have an application that updates a strongly typed data set at run time. I'd like to dynamically create a table that connects to a run time data table. For displaying the data, this works well. ...
5
by: Brian McClellan | last post by:
Just wondering if anyone has a simple example of creating a gridview completely programmatically, i'm not doing anything terribly sophisticated. When creating the gridview declaratively evertying...
0
by: Michael Kellogg | last post by:
I have a problem wherein a query that updates a GridView doesn't seem to really stay in sync with a label I have above the GridView. I have a GridView object that I'm updating with information...
3
by: pblack9455 | last post by:
I have a simple requirement to bind a small ArrayList of (ItemLine) Objects to a GridView control. The Gridview renders on the page and allows me to click update/edit buttons...however the data...
11
by: SAL | last post by:
Hello, I have a Gridview control (.net 2.0) that I'm having trouble getting the Update button to fire any kind of event or preforming the update. The datatable is based on a join so I don't know...
0
by: BizWeb | last post by:
Hi, i am new to ASP.NET. I have write a very simple code to try the updating of the GridView but it is not updating the data. Below is the simple code that i have use. <%@ Page Language="vb"...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.