473,386 Members | 1,673 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,386 software developers and data experts.

In-place Updating in Datagrid not working

A P
Hi!

I have created a sample datagrid that can update data on a database. Please
help me solve the problem, I have attached both aspx and code behind
(aspx.vb):

______________________

datagrid.aspx

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="DataGrid.aspx.vb"
Inherits="vs_2310.DataGrid"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>DataGrid</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:DataGrid id=DataGrid1 style="Z-INDEX: 101; LEFT: 51px; POSITION:
absolute; TOP: 51px" runat="server" DataSource="<%# DataSet21 %>"
DataKeyField="NounID" BorderColor="#CC9966" BorderStyle="None"
BorderWidth="1px" BackColor="White" CellPadding="4" Font-Size="10pt"
AutoGenerateColumns="False" Font-Names="Arial" AllowPaging="True">
<SelectedItemStyle Font-Bold="True" ForeColor="#663399"
BackColor="#FFCC66"></SelectedItemStyle>
<ItemStyle ForeColor="#330099" BackColor="White"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="#FFFFCC"
BackColor="#990000"></HeaderStyle>
<FooterStyle ForeColor="#330099" BackColor="#FFFFCC"></FooterStyle>
<Columns>
<asp:BoundColumn DataField="NounID" SortExpression="NounID"
HeaderText="ID"></asp:BoundColumn>
<asp:BoundColumn DataField="NounDesc" SortExpression="NounDesc"
HeaderText="Noun"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Action">
<ItemTemplate>
<asp:LinkButton runat="server" Text="Edit" CommandName="Edit"
CausesValidation="false"></asp:LinkButton>
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton runat="server" Text="Update"
CommandName="Update"></asp:LinkButton>&nbsp;
<asp:LinkButton runat="server" Text="Cancel" CommandName="Cancel"
CausesValidation="false"></asp:LinkButton>
</EditItemTemplate>
</asp:TemplateColumn>
</Columns>
<PagerStyle HorizontalAlign="Center" ForeColor="#330099"
BackColor="#FFFFCC"></PagerStyle>
</asp:DataGrid>
<asp:Label id="Label1" style="Z-INDEX: 102; LEFT: 51px; POSITION:
absolute; TOP: 17px" runat="server">Label</asp:Label>
</form>
</body>
</HTML>

________________________

datagrid.aspx.vb

Imports System.Data.OleDb
Public Class DataGrid
Inherits System.Web.UI.Page
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
OleDbDataAdapter1.Fill(DataSet21)
DataGrid1.DataBind()
End Sub

Private Sub DataGrid1_EditCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles
DataGrid1.EditCommand
DataGrid1.EditItemIndex() = e.Item.ItemIndex
DataGrid1.DataBind()
End Sub
Private Sub DataGrid1_UpdateCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles
DataGrid1.UpdateCommand
Dim NounTable As DataSet2.tbltsNounDataTable

NounTable = DataSet21.tbltsNoun

Dim rowToUpdate As DataSet2.tbltsNounRow

rowToUpdate = NounTable.Rows(e.Item.ItemIndex)
rowToUpdate.NounDesc = CType(e.Item.Cells(1).Controls(0),
TextBox).Text

OleDbDataAdapter1.Update(DataSet21)
Label1.Text = rowToUpdate.NounDesc

DataGrid1.EditItemIndex = -1
DataGrid1.DataBind()
End Sub

Private Sub DataGrid1_PageIndexChanged(ByVal source As Object, ByVal e
As System.Web.UI.WebControls.DataGridPageChangedEvent Args) Handles
DataGrid1.PageIndexChanged
DataGrid1.CurrentPageIndex = e.NewPageIndex
DataGrid1.DataBind()
End Sub

Private Sub DataGrid1_CancelCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles
DataGrid1.CancelCommand
DataGrid1.EditItemIndex = -1
DataGrid1.DataBind()
End Sub
End Class

___________________
Nov 19 '05 #1
9 1563
Hey, A P,

what *is* the problem you have ?

Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

"A P" <ap@textguru.ph> wrote in message
news:um**************@TK2MSFTNGP15.phx.gbl...
Hi!

I have created a sample datagrid that can update data on a database.
Please
help me solve the problem, I have attached both aspx and code behind
(aspx.vb):


....code snipped.
Nov 19 '05 #2
A P
Data is not updating. I've already check on the database and the content is
not changed if I click on the update link. I'm using MS Access for the
database.

Me

"Juan T. Llibre" <no***********@nowhere.com> wrote in message
news:#3**************@TK2MSFTNGP09.phx.gbl...
Hey, A P,

what *is* the problem you have ?

Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

"A P" <ap@textguru.ph> wrote in message
news:um**************@TK2MSFTNGP15.phx.gbl...
Hi!

I have created a sample datagrid that can update data on a database.
Please
help me solve the problem, I have attached both aspx and code behind
(aspx.vb):


...code snipped.

Nov 19 '05 #3
I cut out the other newsgroups.

Are you getting any errors ?
If you are, please post the error text.

Did you write that code, or is that a sample from somewhere ?
If it is a sample from somewhere, did you change anything ?
If you did, what did you change ?

Does you database content display, but it just doesn't update ?

Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

"A P" <ap@textguru.ph> wrote in message
news:uD**************@TK2MSFTNGP15.phx.gbl...
Data is not updating. I've already check on the database and the content
is
not changed if I click on the update link. I'm using MS Access for the
database.

Me

"Juan T. Llibre" <no***********@nowhere.com> wrote in message
news:#3**************@TK2MSFTNGP09.phx.gbl...
Hey, A P,

what *is* the problem you have ?

Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

"A P" <ap@textguru.ph> wrote in message
news:um**************@TK2MSFTNGP15.phx.gbl...
> Hi!
>
> I have created a sample datagrid that can update data on a database.
> Please
> help me solve the problem, I have attached both aspx and code behind
> (aspx.vb):
>


...code snipped.


Nov 19 '05 #4
A P
No error.

The code was from MSDN
website.(http://msdn.microsoft.com/library/de...brary/en-us/vb
con/html/vbtskallowinguserstoedititemsindatagridwebcontrol. asp)

I can view the datagrid, click on edit and can cancel data. But when I will
click on update, the view will return back to edit mode(without textbox) and
the content is not changed.

"Juan T. Llibre" <no***********@nowhere.com> wrote in message
news:uo**************@tk2msftngp13.phx.gbl...
I cut out the other newsgroups.

Are you getting any errors ?
If you are, please post the error text.

Did you write that code, or is that a sample from somewhere ?
If it is a sample from somewhere, did you change anything ?
If you did, what did you change ?

Does you database content display, but it just doesn't update ?

Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

"A P" <ap@textguru.ph> wrote in message
news:uD**************@TK2MSFTNGP15.phx.gbl...
Data is not updating. I've already check on the database and the content
is
not changed if I click on the update link. I'm using MS Access for the
database.

Me

"Juan T. Llibre" <no***********@nowhere.com> wrote in message
news:#3**************@TK2MSFTNGP09.phx.gbl...
Hey, A P,

what *is* the problem you have ?

Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

"A P" <ap@textguru.ph> wrote in message
news:um**************@TK2MSFTNGP15.phx.gbl...
> Hi!
>
> I have created a sample datagrid that can update data on a database.
> Please
> help me solve the problem, I have attached both aspx and code behind
> (aspx.vb):
>

...code snipped.



Nov 19 '05 #5
Sometimes it's hard to get piecemeal
code to work as we want it do.

Let me suggest yo you that you take a good look
at a complete page which does what you want.

Datagrid6.aspx is in the QuickStart samples,
and you can see it working online at :
http://www.dotnetjunkies.com/quickst...datagrid6.aspx

The source code for that datagrid edit page is at :
http://www.dotnetjunkies.com/quickst.../datagrid6.src
in both VB and C#

You'll find that sample a lot easier to dissect,
study, and then modify for your own use.

Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

"A P" <ap@textguru.ph> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
No error.

The code was from MSDN
website.(http://msdn.microsoft.com/library/de...brary/en-us/vb
con/html/vbtskallowinguserstoedititemsindatagridwebcontrol. asp)

I can view the datagrid, click on edit and can cancel data. But when I
will
click on update, the view will return back to edit mode(without textbox)
and
the content is not changed.

"Juan T. Llibre" <no***********@nowhere.com> wrote in message
news:uo**************@tk2msftngp13.phx.gbl...
I cut out the other newsgroups.

Are you getting any errors ?
If you are, please post the error text.

Did you write that code, or is that a sample from somewhere ?
If it is a sample from somewhere, did you change anything ?
If you did, what did you change ?

Does you database content display, but it just doesn't update ?

Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

"A P" <ap@textguru.ph> wrote in message
news:uD**************@TK2MSFTNGP15.phx.gbl...
> Data is not updating. I've already check on the database and the
> content
> is
> not changed if I click on the update link. I'm using MS Access for the
> database.
>
> Me
>
> "Juan T. Llibre" <no***********@nowhere.com> wrote in message
> news:#3**************@TK2MSFTNGP09.phx.gbl...
>> Hey, A P,
>>
>> what *is* the problem you have ?
>>
>>
>>
>> Juan T. Llibre
>> ASP.NET MVP
>> http://asp.net.do/foros/
>> Foros de ASP.NET en Español
>> Ven, y hablemos de ASP.NET...
>> ======================
>>
>> "A P" <ap@textguru.ph> wrote in message
>> news:um**************@TK2MSFTNGP15.phx.gbl...
>> > Hi!
>> >
>> > I have created a sample datagrid that can update data on a database.
>> > Please
>> > help me solve the problem, I have attached both aspx and code behind
>> > (aspx.vb):
>> >
>>
>> ...code snipped.
>>
>>
>
>



Nov 19 '05 #6
AP,

This is a lot of code, first of all would I change what happen in the load
event in something like this (typed in this message so watch typos).
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not IsPostBack then
OleDbDataAdapter1.Fill(DataSet21)
session.item("ds21") = DataSet21
Else
Dataset21 = directcast(session.Item("ds21"), dataset)
End if
DataGrid1.DataSource = Dataset21
DataGrid1.DataBind()
End Sub

And than see what happens.

Cor
Nov 19 '05 #7
A P
Cor,

Same output. No change on the field. Much better, if its OK with you to post
a simple code that uses Datagrid on Access Database that can update values.
Hope that you'll grant my request.

regards,
Me

"Cor Ligthert" <no************@planet.nl> wrote in message
news:u9**************@TK2MSFTNGP14.phx.gbl...
AP,

This is a lot of code, first of all would I change what happen in the load
event in something like this (typed in this message so watch typos).
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not IsPostBack then
OleDbDataAdapter1.Fill(DataSet21)
session.item("ds21") = DataSet21
Else
Dataset21 = directcast(session.Item("ds21"), dataset)
End if
DataGrid1.DataSource = Dataset21
DataGrid1.DataBind()
End Sub

And than see what happens.

Cor

Nov 19 '05 #8
AP,
Same output. No change on the field. Much better, if its OK with you to
post
a simple code that uses Datagrid on Access Database that can update
values.
Hope that you'll grant my request.


At your service, I never use the designer so it was more work than I thought

\\\
'This is a simple project without any error trapping
'Create a new project
'Select an oledbdataadapter
'Use a Northwind MDB
'Select Employees and from that EmployeeID, FirstName, LastName
'Generate a dataset
'Drag a datagrid and set in the propertybuilder the datasource, datamember
'set the Edit, Cancel, Update column, datacolumns in the sequence Id,
FirstName, Lastname

'And than this code
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
OleDbDataAdapter1.Fill(DataSet11)
Session.Item("ds21") = DataSet11
DataGrid1.DataBind()
Else
DataSet11 = DirectCast(Session.Item("ds21"), DataSet1)
End If
DataGrid1.DataSource = DataSet11
End Sub
Private Sub DataGrid1_EditCommand(ByVal source As Object, ByVal e As _
System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles _
DataGrid1.EditCommand
DataGrid1.EditItemIndex() = e.Item.ItemIndex
DataGrid1.DataBind()
End Sub
Private Sub DataGrid1_UpdateCommand(ByVal source As Object, ByVal e As _
System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles _
DataGrid1.UpdateCommand
Dim dv As New DataView(DataSet11.Employees)
dv.RowFilter = "EmployeeID = '" _
& DirectCast(e.Item.Cells(1).Controls(0), TextBox).Text & "'"
dv(0)("FirstName") = DirectCast(e.Item.Cells(2).Controls(0),
TextBox).Text
dv(0)("LastName") = DirectCast(e.Item.Cells(3).Controls(0),
TextBox).Text
OleDbDataAdapter1.Update(DataSet11.Employees)
Session.Item("ds21") = DataSet11
DataGrid1.DataBind()
End Sub
Private Sub DataGrid1_CancelCommand(ByVal source As Object, ByVal e As _
System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles _
DataGrid1.CancelCommand
DataGrid1.EditItemIndex = -1
DataGrid1.DataBind()
End Sub
End Class
///
Nov 19 '05 #9
A P
Thanks Cor! I already made it but I need to study first the code since I
have no idea on the "Session.Item" thing and "DirectCast". Thanks again.
"Cor Ligthert" <no************@planet.nl> wrote in message
news:OU**************@TK2MSFTNGP09.phx.gbl...
AP,
Same output. No change on the field. Much better, if its OK with you to
post
a simple code that uses Datagrid on Access Database that can update
values.
Hope that you'll grant my request.

At your service, I never use the designer so it was more work than I

thought
\\\
'This is a simple project without any error trapping
'Create a new project
'Select an oledbdataadapter
'Use a Northwind MDB
'Select Employees and from that EmployeeID, FirstName, LastName
'Generate a dataset
'Drag a datagrid and set in the propertybuilder the datasource, datamember
'set the Edit, Cancel, Update column, datacolumns in the sequence Id,
FirstName, Lastname

'And than this code
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
OleDbDataAdapter1.Fill(DataSet11)
Session.Item("ds21") = DataSet11
DataGrid1.DataBind()
Else
DataSet11 = DirectCast(Session.Item("ds21"), DataSet1)
End If
DataGrid1.DataSource = DataSet11
End Sub
Private Sub DataGrid1_EditCommand(ByVal source As Object, ByVal e As _
System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles _
DataGrid1.EditCommand
DataGrid1.EditItemIndex() = e.Item.ItemIndex
DataGrid1.DataBind()
End Sub
Private Sub DataGrid1_UpdateCommand(ByVal source As Object, ByVal e As _ System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles _
DataGrid1.UpdateCommand
Dim dv As New DataView(DataSet11.Employees)
dv.RowFilter = "EmployeeID = '" _
& DirectCast(e.Item.Cells(1).Controls(0), TextBox).Text & "'"
dv(0)("FirstName") = DirectCast(e.Item.Cells(2).Controls(0),
TextBox).Text
dv(0)("LastName") = DirectCast(e.Item.Cells(3).Controls(0),
TextBox).Text
OleDbDataAdapter1.Update(DataSet11.Employees)
Session.Item("ds21") = DataSet11
DataGrid1.DataBind()
End Sub
Private Sub DataGrid1_CancelCommand(ByVal source As Object, ByVal e As _ System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles _
DataGrid1.CancelCommand
DataGrid1.EditItemIndex = -1
DataGrid1.DataBind()
End Sub
End Class
///

Nov 19 '05 #10

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

Similar topics

3
by: Curious Expatriate | last post by:
Hi- I'm completely stumped. I'm trying to write some code that will parse a file and rewrite it with all URLs replaced by something else. For example: if the file looks like this: <b>click...
1
by: JS Bangs | last post by:
I started using PHP's object-oriented stuff a little while ago, which has mostly been a joy. However, I've noticed that they don't seem to echo as I would like. Eg: $this->field = 255;...
5
by: lawrence | last post by:
I've waited 6 weeks for an answer to my other question and still no luck, so let me rephrase the question. I know I can do this: <form method="post" action="$self"> <input type="text"...
0
by: Ben Eisenberg | last post by:
I'm trying to run a php script setuid. I've tried POSIX_setuid but you have to be root to run this. The files are located on a public access unix system and have me as the owner and nobody as the...
2
by: Felix | last post by:
Hi, I've a problem: I want to have the result of my Mysql Query in a Table in my php file. Now I've this: <?
1
by: James | last post by:
What is the best way to update a record in a MYSQL DB using a FORM and PHP ? Where ID = $ID ! Any examples or URLS ? Thanks
1
by: phpkid | last post by:
Howdy I've been given conflicting answers about search engines picking up urls like: http://mysite.com/index.php?var1=1&var2=2&var3=3 Do search engines pick up these urls? I've been considering...
1
by: lawrence | last post by:
What is the PHP equivalent of messaging, as in Java?
3
by: Quinten Carlson | last post by:
Is there a way to conditionally define a function in php? I'm trying to run a php page 10 times using the include statement, but I get an error because my function is already defined. The docs...
2
by: Phillip Wu | last post by:
Hi, I saw a previous post about sending arrays but did not quite understand the answers. The problem is that I would like to pass an entire array as a hidden input field from one php script...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.