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="Defau lt.aspx.cs" Inherits="_Defa ult" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitl ed Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server"
AutoGenerateCol umns="False" DataKeyNames="O rderID"
DataSourceID="S qlDataSource1" AllowPaging="Tr ue"
AllowSorting="T rue" OnRowDataBound= "GridView1_RowD ataBound"
OnRowUpdated="G ridView1_RowUpd ated"
OnRowUpdating=" GridView1_RowUp dating">
<Columns>
<asp:CommandFie ld ShowSelectButto n="True"
ShowEditButton= "True" />
<asp:BoundFie ld DataField="Orde rID"
HeaderText="Ord erID" InsertVisible=" False" ReadOnly="True"
SortExpression= "OrderID" />
<asp:BoundFie ld DataField="Cust omerID"
HeaderText="Cus tomerID" SortExpression= "CustomerID " />
<asp:BoundFie ld DataField="Orde rDate"
HeaderText="Ord erDate" SortExpression= "OrderDate" />
<asp:BoundFie ld DataField="Ship City"
HeaderText="Shi pCity" SortExpression= "ShipCity" />
<asp:TemplateFi eld HeaderText="Emp loyeeID"
SortExpression= "EmployeeID ">
<ItemTemplate >
<asp:GridView ID="GridView2" runat="server"
AutoGenerateCol umns="False"
DataKeyNames="E mployeeID" DataSourceID="S qlDataSource2">
<Columns>
<asp:CommandFie ld ShowSelectButto n="True"
ShowEditButton= "True" />
<asp:BoundFie ld DataField ="EmployeeID " />
<asp:BoundFie ld DataField="Last Name" />
<asp:BoundFie ld DataField ="FirstName" />
<asp:BoundFie ld DataField ="Title" />
<asp:TemplateFi eld HeaderText="Cit y">
<EditItemTempla te>
<asp:TextBox ID="TextBox1"
runat="server"> </asp:TextBox>
</EditItemTemplat e>
<ItemTemplate >
<asp:Label ID="Label1"
runat="server" Text='<%# Bind("City") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateFie ld>
</Columns>
</asp:GridView>
<asp:SqlDataSou rce ID="SqlDataSour ce2"
runat="server" ConnectionStrin g="<%$
ConnectionStrin gs:NorthwindCon nectionString %>" SelectCommand=' <%#
Eval("EmployeeI D", "Select EmployeeID, LastName, FirstName, Title, City
from Employees where EmployeeID={0}" )%>' UpdateCommand = '<%#
Eval("EmployeeI d" , "update employees set
firstname=@firs tname,lastname= @lastname,title =@title,city=@c ity where
employeeid={0}" )%>'></asp:SqlDataSour ce>
</ItemTemplate>
</asp:TemplateFie ld>
</Columns>
</asp:GridView>
<asp:SqlDataSou rce ID="SqlDataSour ce1"
OldValuesParame terFormatString ="original_{ 0}"
runat="server" ConnectionStrin g="<%$
ConnectionStrin gs:NorthwindCon nectionString %>"
SelectCommand=" select * from orders" UpdateCommand=" update
orders set
customerid=@cus tomerid,orderda te=@orderdate,s hipcity=@shipci ty where
employeeid=@emp loyeeid">
<UpdateParamete rs>
<asp:Paramete r Name="customeri d" />
<asp:Paramete r Name="orderdate " />
<asp:Paramete r Name="shipcity" />
<asp:Paramete r Name="employeei d" />
<asp:Paramete r Name="orderid" />
</UpdateParameter s>
</asp:SqlDataSour ce>
</div>
</form>
</body>
</html>
Any help is greatly appreciated.
Thanks in advance 1 1795
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="Defau lt.aspx.cs" Inherits="_Defa ult" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitl ed Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:GridView ID="GridView1" runat="server" AutoGenerateCol umns="False" DataKeyNames="O rderID" DataSourceID="S qlDataSource1" AllowPaging="Tr ue" AllowSorting="T rue" OnRowDataBound= "GridView1_RowD ataBound" OnRowUpdated="G ridView1_RowUpd ated" OnRowUpdating=" GridView1_RowUp dating"> <Columns> <asp:CommandFie ld ShowSelectButto n="True" ShowEditButton= "True" /> <asp:BoundFie ld DataField="Orde rID" HeaderText="Ord erID" InsertVisible=" False" ReadOnly="True" SortExpression= "OrderID" /> <asp:BoundFie ld DataField="Cust omerID" HeaderText="Cus tomerID" SortExpression= "CustomerID " /> <asp:BoundFie ld DataField="Orde rDate" HeaderText="Ord erDate" SortExpression= "OrderDate" /> <asp:BoundFie ld DataField="Ship City" HeaderText="Shi pCity" SortExpression= "ShipCity" /> <asp:TemplateFi eld HeaderText="Emp loyeeID" SortExpression= "EmployeeID "> <ItemTemplate > <asp:GridView ID="GridView2" runat="server" AutoGenerateCol umns="False" DataKeyNames="E mployeeID" DataSourceID="S qlDataSource2"> <Columns> <asp:CommandFie ld ShowSelectButto n="True" ShowEditButton= "True" /> <asp:BoundFie ld DataField ="EmployeeID " /> <asp:BoundFie ld DataField="Last Name" /> <asp:BoundFie ld DataField ="FirstName" /> <asp:BoundFie ld DataField ="Title" /> <asp:TemplateFi eld HeaderText="Cit y"> <EditItemTempla te> <asp:TextBox ID="TextBox1" runat="server"> </asp:TextBox> </EditItemTemplat e> <ItemTemplate > <asp:Label ID="Label1" runat="server" Text='<%# Bind("City") %>'></asp:Label> </ItemTemplate> </asp:TemplateFie ld> </Columns> </asp:GridView> <asp:SqlDataSou rce ID="SqlDataSour ce2" runat="server" ConnectionStrin g="<%$ ConnectionStrin gs:NorthwindCon nectionString %>" SelectCommand=' <%# Eval("EmployeeI D", "Select EmployeeID, LastName, FirstName, Title, City from Employees where EmployeeID={0}" )%>' UpdateCommand = '<%# Eval("EmployeeI d" , "update employees set firstname=@firs tname,lastname= @lastname,title =@title,city=@c ity where employeeid={0}" )%>'></asp:SqlDataSour ce> </ItemTemplate> </asp:TemplateFie ld> </Columns> </asp:GridView> <asp:SqlDataSou rce ID="SqlDataSour ce1" OldValuesParame terFormatString ="original_{ 0}" runat="server" ConnectionStrin g="<%$ ConnectionStrin gs:NorthwindCon nectionString %>" SelectCommand=" select * from orders" UpdateCommand=" update orders set customerid=@cus tomerid,orderda te=@orderdate,s hipcity=@shipci ty where employeeid=@emp loyeeid"> <UpdateParamete rs> <asp:Paramete r Name="customeri d" /> <asp:Paramete r Name="orderdate " /> <asp:Paramete r Name="shipcity" /> <asp:Paramete r Name="employeei d" /> <asp:Paramete r Name="orderid" /> </UpdateParameter s> </asp:SqlDataSour ce>
</div> </form> </body> </html>
Any help is greatly appreciated. Thanks in advance
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 the applicable fields in the gridview to a
sqldatasource which in turn calls a sproc with the appropriate parameters and
data. Any ideas?
Thanks in advance,
|
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
correctly but it is not updating or deleting the rows. What I did was, in
design view, added a gridview control and added an sqldatasource control. I
configured the data source to update and delete. In the gridview tasks I
selected enable...
|
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 select, remember it, and
then use it in the update. It works just fine when I have full control of the
whole process.
I want to do the same for my GridView/SqlDataSource combinations. I
typically select from a view and update the corresponding...
|
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
re-format the updated row fields.
I have looked at gridView.rowUpdated method, but cannot figure out
how....
|
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. I just set the
GridView.DataSource once, and call DataBind();
I'd like to drive the application from the GridView control, by including
command buttons that allow editing of the data. Starting out simple, I
have a DataTable with a boolean...
| |
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 works fine, however
programmatically, while the grid will display data that exsists in the
database, any operation on the data ( editing/updating/deleting ) seems to
cause a rowdeleting/updating etc error. Or is this simply not meant to be
done?
|
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 whenever my
user enters a job number into a textbox and hits a button. There is a
SQLDataSource object on the page that does the retrieval of the data, and
the job number parameter for its query is bound to the textbox "Text"
value. In the button...
|
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 does not change, and in the
updated and updating row events the newValues collections are empty!!!
I've tried various other methods such as using an ObjectDataSource, but my
ArrayList does not existing in a database until after the editing and...
|
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 if that's what's causing the
behavior or not. It seems like the Update button should at least do
something.
When the Edit button is clicked, the grid goes into Edit mode and the Cancel
button takes the grid out of Edit mode. So, I don't get what...
|
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" AutoEventWireup="false"
CodeBehind="Default.aspx.vb" Inherits="WebApplication1._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |