473,608 Members | 2,443 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Datagridview Won't stay updated

I am posting this for a coworker.

--------------------------------------------------------

The issue i'm having is after i enter all my data into my gridview's
textboxes and dropdownlists the data wont stick. My object data source dumps
to a class but after the update the grid should read from the class as well.
After the update button is clicked all the data passes through the class
like it should and doesn't throw any errors. After all the data moves
through the class and the page reloads, it looks like it's adding a new
line. I am new to using "OOP" so my class's may be a bit off. I was told by
a co-worker that i should have an update method and not use the same insert
method? As this may be the issue, if someone could please take look at my
class and show me what an actual update method is. The commented portion of
my class below was my attempt at building an update method.
All help is greatly appreciated. Thanks!
ASPX code
<asp:GridView ID="pogrid" runat="server"
AutoGenerateCol umns="False"
style="margin-left: 0px; margin-right: 0px; margin-bottom: 0px"
Width="1020px" BorderColor="Bl ack" BorderStyle="So lid"
CellPadding="4"
BackColor="Whit e" BorderWidth="1p x"
ForeColor="Blac k"
GridLines="Vert ical" HorizontalAlign ="Center"
BackImageUrl="~/POTracking/images/buttontemplate. jpg"
Font-Names="Calibri" DataSourceID="O bjectDataSource 1">
<FooterStyle BackColor="#CCC C99" />
<RowStyle BackColor="#E1E 3EC" BorderColor="Bl ack"
BorderStyle="So lid"
BorderWidth="1p x" Font-Names="Calibri"
HorizontalAlign ="Center" />
<Columns>

<asp:CommandFie ld ButtonType="Ima ge"
DeleteImageUrl= "~/POTracking/images/Deletesmall.png "
ShowCancelButto n="False" ShowDeleteButto n="True"
ShowEditButton= "True"
EditImageUrl="~/POTracking/images/Document.png"
ShowInsertButto n="True"
UpdateImageUrl= "~/POTracking/images/Sync.png" />
<asp:TemplateFi eld HeaderText="QTY "
SortExpression= "Quantity">
<headerstyle width="36px" />
<EditItemTempla te>
<asp:TextBox ID="qtybox" runat="server" width="32px"
Text='<%# Bind("Quantity" , "{0}")
%>'></asp:TextBox>
</EditItemTemplat e>
<ItemTemplate >
<asp:Label ID="qtylbl" runat="server" Text='<%#
Bind("Quantity" ) %>'></asp:Label>
</ItemTemplate>
<HeaderStyle Width="40px" />
</asp:TemplateFie ld>
<asp:TemplateFi eld HeaderText="Bil l To"
SortExpression= "Billto" >
<headerstyle width="85px" />
<EditItemTempla te>
<asp:DropDownLi st ID="billtobox" runat="server"
DataSourceID="b illto"
DataTextField=" name" datavaluefield= "id"
Width="79px"
SelectedValue=' <%# Bind("Billto", "{0}") %>'
appenddatabound items="true">
<asp:ListItem Value="0">Selec t</asp:ListItem>
</asp:DropDownLis t>
<asp:SqlDataSou rce ID="billto" runat="server"
ConnectionStrin g="<%$
ConnectionStrin gs:POTracking %>" SelectCommand=" billto"
SelectCommandTy pe="StoredProce dure"></asp:SqlDataSour ce>
</EditItemTemplat e>
<ItemTemplate >
<asp:Label ID="billtolbl"
runat="server"> </asp:Label>
</ItemTemplate>
</asp:TemplateFie ld>

<asp:TemplateFi eld HeaderText="Des cription"
SortExpression= "Descriptio n">
<headerstyle width="454px" />
<EditItemTempla te>
<asp:TextBox ID="descbox" width="450px"
runat="server" Text='<%# Bind("Descripti on") %>'></asp:TextBox>
</EditItemTemplat e>
<ItemTemplate >
<asp:Label ID="desclbl" runat="server" Text='<%#
Bind("Descripti on") %>'></asp:Label>
</ItemTemplate>

</asp:TemplateFie ld>
<asp:TemplateFi eld HeaderText="Typ e" SortExpression= "Type">
<headerstyle width="44px" />
<EditItemTempla te>
<asp:DropDownLi st ID="typebox" runat="server"
width="40px" appenddatabound items="True"
DataSourceID="s eltype" DataTextField=' typeabbr'
DataValueField= "id" SelectedValue=' <%#
Bind("Type", "{0}") %>'>
<asp:ListItem Value="0">Selec t</asp:ListItem>
</asp:DropDownLis t>
<asp:SqlDataSou rce ID="seltype" runat="server"
ConnectionStrin g="<%$
ConnectionStrin gs:POTracking %>" SelectCommand=" type"
SelectCommandTy pe="StoredProce dure"></asp:SqlDataSour ce>
</EditItemTemplat e>
<ItemTemplate >
<asp:Label ID="typelbl" runat="server" Text='<%#
Bind("Type") %>'></asp:Label>
</ItemTemplate>
<HeaderStyle Width="46px" />
</asp:TemplateFie ld>
<asp:TemplateFi eld HeaderText="Pro ject"
SortExpression= "project">
<headerstyle width="110px" />
<EditItemTempla te>
<asp:DropDownLi st ID="projbox" runat="server"
DataSourceID="P rojectrd"
DataTextField=" name" DataValueField= "Projectid"
width="106px"
SelectedValue=' <%# Bind("project", "{0}") %>'
appenddatabound items="true">
<asp:ListItem Value="0">Selec t</asp:ListItem>
</asp:DropDownLis t>
<asp:SqlDataSou rce ID="Projectrd" runat="server"
ConnectionStrin g="<%$
ConnectionStrin gs:POTracking %>" SelectCommand=" proj"
SelectCommandTy pe="StoredProce dure"></asp:SqlDataSour ce>
</EditItemTemplat e>
<ItemTemplate >
<asp:Label ID="projlbl" runat="server" Text='<%#
Bind("project") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateFie ld>
<asp:TemplateFi eld HeaderText="Uni t Price"
SortExpression= "UnitPrice" >
<headerstyle width="79px" />
<EditItemTempla te>
<asp:TextBox ID="unitpricebo x" width="75px"
runat="server"
Text='<%# Bind("UnitPrice ", "{0:N}") %>'
Height="22px"></asp:TextBox>
</EditItemTemplat e>
<ItemTemplate >
<asp:Label ID="unitpricelb l" runat="server"
Text='<%# Bind("UnitPrice ") %>'></asp:Label>
</ItemTemplate>

</asp:TemplateFie ld>
<asp:TemplateFi eld HeaderText="Tot al"
SortExpression= "Total">
<headerstyle width="79px" />
<EditItemTempla te>
<asp:TextBox ID="Totalbox" runat="server"
BackColor="Silv er"
BorderColor="Bl ack" Text='<%# Bind("Total",
"{0:N}") %>' ReadOnly="True" ></asp:TextBox>
</EditItemTemplat e>
<ItemTemplate >
<asp:Label ID="totallbl" runat="server" Text='<%#
Bind("Total") %>'></asp:Label>
</ItemTemplate>

</asp:TemplateFie ld>
</Columns>
<PagerStyle BackColor="#F7F 7DE" ForeColor="Blac k"
HorizontalAlign ="Right" />
<SelectedRowSty le BackColor="#CE5 D5A" Font-Bold="True"
ForeColor="Whit e" />
<HeaderStyle Wrap="False" BorderColor="Bl ack"
BorderStyle="So lid"
BorderWidth="1p x" />
<AlternatingRow Style BackColor="#C7C 7C7" />
</asp:GridView>

VB.Net Code
<asp:ObjectData Source ID="ObjectDataS ource1" runat="server"
SelectMethod="A ddPOLines" TypeName="POTra cker.Purchase_O rder"
InsertMethod="A ddPOLines"
EnableCaching=" True" UpdateMethod="A ddPOLines">
<UpdateParamete rs>
<asp:Paramete r Name="Quantity" Type="Int32" />
<asp:Paramete r Name="billto" Type="Int32" />
<asp:Paramete r Name="descripti on" Type="String" />
<asp:Paramete r Name="type" Type="String" />
<asp:Paramete r Name="project" Type="Int32" />
<asp:Paramete r Name="UnitPrice " Type="Double" />
<asp:Paramete r Name="total" Type="Double" />
</UpdateParameter s>
<InsertParamete rs>
<asp:Paramete r Name="Quantity" Type="Int32" />
<asp:Paramete r Name="billto" Type="Int32" />
<asp:Paramete r Name="descripti on" Type="String" />
<asp:Paramete r Name="type" Type="String" />
<asp:Paramete r Name="project" Type="Int32" />
<asp:Paramete r Name="UnitPrice " Type="Double" />
<asp:Paramete r Name="total" Type="Double" />
</InsertParameter s>
</asp:ObjectDataS ource>

<asp:Button ID="add" runat="server" Text="New Row" />

VB.Net
Imports System.Security
Imports System.Security .Principal.Wind owsIdentity
Imports Microsoft.Appli cationBlocks
Partial Public Class create

Inherits System.Web.UI.P age

Private Sub pogrid_RowEditi ng(ByVal sender As Object, ByVal e As
System.Web.UI.W ebControls.Grid ViewEditEventAr gs) Handles pogrid.RowEditi ng
pogrid.EditInde x = e.NewEditIndex
End Sub

Private Sub pogrid_RowUpdat ed(ByVal sender As Object, ByVal e As
System.Web.UI.W ebControls.Grid ViewUpdatedEven tArgs) Handles
pogrid.RowUpdat ed
pogrid.EditInde x = -1
If e.Exception IsNot Nothing Then
'Do something
End If
End Sub
Protected Sub add_Click(ByVal sender As Object, ByVal e As EventArgs)
Handles add.Click
ObjectDataSourc e1.Insert()
End Sub
End Class
VB.Net Class
Public Class Purchase_Order
Dim _polines As List(Of POLine) = New List(Of POLine)
Dim _poNumber As String = String.Empty

Public Property Number() As String
Get
Return _poNumber

End Get
Set(ByVal value As String)
_poNumber = value
End Set
End Property

Public Function AddPOLines(ByVa l Quantity As Integer, ByVal billto As
Integer, ByVal description As String, ByVal type As String, ByVal project As
Integer, ByVal UnitPrice As Double, ByVal total As Double) As POLine
Dim newline As POLine = Me.AddPOLines

newline.Quantit y = Quantity
newline.Billto = billto
newline.Descrip tion = description
newline.Type = type
newline.project = project
newline.UnitPri ce = UnitPrice
newline.Total = total
Return newline
End Function

'Public Function upPOLines(ByVal Quantity As Integer, ByVal billto As
Integer, ByVal description As String, ByVal type As String, ByVal project As
Integer, ByVal UnitPrice As Double, ByVal unittotal As Double) As POLine
' Dim updateln As POLine = Me.upPOLines

' Quantity = updateln.Quanti ty
' billto = updateln.Billto
' description = updateln.Descri ption
' type = updateln.Type
' project = updateln.projec t
' UnitPrice = updateln.UnitPr ice
' unittotal = updateln.Total
' Return updateln
'End Function

Public Function AddPOLines() As POLine
Dim newline As POLine = New POLine
_polines.Add(ne wline)
Return newline
End Function
'Public Function upPOLines() As POLine
' Dim updateln As POLine = New POLine
' _polines.Add(up dateln)
' Return updateln
'End Function

Public Property POLines() As List(Of POLine)
Get
Return _polines
End Get
Set(ByVal value As List(Of POLine))
_polines = value
End Set
End Property

End Class
Public Class POLine
Dim _quantity As Integer
Dim _billto As Integer
Dim _description As String
Dim _type As Integer
Dim _projectitem As Integer
Dim _unitprice As Decimal
Dim _total As Decimal
Public Property Quantity() As Integer
Get
Return _quantity
End Get
Set(ByVal value As Integer)
_quantity = value
End Set
End Property

Public Property Billto() As Integer
Get
Return _billto
End Get
Set(ByVal value As Integer)
_billto = value
End Set
End Property

Public Property Description() As String
Get
Return _description
End Get
Set(ByVal value As String)
_description = value
End Set
End Property

Public Property Type() As Integer
Get
Return _type
End Get
Set(ByVal value As Integer)
_type = value
End Set
End Property
Public Property project() As Integer
Get
Return _projectitem
End Get
Set(ByVal value As Integer)
_projectitem = value
End Set
End Property
Public Property UnitPrice() As Decimal
Get
Return _unitprice
End Get
Set(ByVal value As Decimal)
_unitprice = value
End Set
End Property

Public Property Total() As Decimal
Get
Return _total
End Get
Set(ByVal value As Decimal)
_total = value
End Set
End Property

End Class
Jun 27 '08 #1
1 1995
Landry, Eric wrote:
I am posting this for a coworker.
There was no way for you to know it (except maybe by browsing through some
of the previous questions in this newsgroup before posting yours - always a
recommended practice) , but this is a classic (COM-based) asp newsgroup.
ASP.Net bears very little resemblance to classic ASP so, while you may be
lucky enough to find a dotnet-knowledgeable person here who can answer your
question, you can eliminate the luck factor by posting your question to a
group where those dotnet-knowledgeable people hang out. I suggest
microsoft.publi c.dotnet.framew ork.aspnet or the forums at www.asp.net.

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jun 27 '08 #2

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

Similar topics

0
4098
by: T.Haugnes | last post by:
I've installed visual studio c# express, .net SDK 2.0, SQL Server Express, created a table in the SQL database and filled this with some data-rows. I dragged the database-table from Data Source-pane to the Form-designer to created a datagridview-form. When I then build and run the program the datagridview is nicely filled with database-data. But when I add or modify the data inside the datagridview in the running program the database...
1
18823
by: Dave A | last post by:
Hi, I am struggling with two way databinding in WinForms and the DataGridView. I am binding to business object classes (rather than datatables). If I have a collection of these business objects that is the datasource of a DataBinding that is bound to a DataGridView (WinForms) then I was expecting that any change to the data would be reflected in the DataGridView (in other words I was expecting the 2 way databinding to actually...
1
3743
by: David | last post by:
I have a realtime stock quote system developed where I am updating a typed dataset with realtime quotes. I want my DataGridView control to show green forecolor when a price moves up and red forecolor when a price moves down. I am using the cellvaluechanged event of the DataGridView control and thought it would be fired when the Dataset(the DataGridView's datasource) is updated. CellValueChanged is not fired when the dataset is updated. ...
0
881
by: Bob | last post by:
I got a 2datagridviews bound to sql serve tables , one parent one child. The changes are always made only to the child table (add, edit or delete) In the Child table definition in SQL server I have an automatic generation via trigger of the date record is modified and the user name of the modifier. When I hit the dataset.Update code My saves are done OK, all the info is there when I look at it in sql server, but I do not see the...
4
4851
by: =?Utf-8?B?UmljaA==?= | last post by:
On a form - I have a datagridview which is docked to the entire form. The datagridview allows users to Delete and/or Add Rows. On the Form_Load event I Fill the datagridview source table with a sql DataAdapter (da) da.SelectCommand.CommandText = "Select * from Servertbl1" da.Fill(ds, "tbl1") so far, so good. If I add a row to the datagridview I use the following sqlDataAdapter code to update the server table - which works OK when...
1
8496
by: =?Utf-8?B?RGF0YUdyaWRWaWV3IGFkZCByb3cgZHluYW1pY2Fs | last post by:
Hi, I am working on the windows application. I created a form Form1 to list records. I used datagridview to show data and bound it to a dataadapter. User can click Update button in Form1 to open a new dialog window Form2 to update selected record and also add new records. When user closes the Form2, the Form1's records should be updated (New records should be added and updated record should be updated.) And we also want to stay in the...
2
2215
by: snowdog17 | last post by:
Hello, I am a student and I need help with my VB task. I am currently using VB 2005 Express and I am fairly new to it, although I have programed in Delphi before. -------------------------------------- My Problem is this: -------------------------------------- I have 2 forms. The first form contains a DataGridView and a button. The DataGridView is bound to an access database, and loads at form_load. The second form contains several...
11
76126
by: dave18 | last post by:
Hello all! I found a solution to my original question, but there's still so much I don't understand about it, I thought I'd give this forum a try. At the very least, maybe it will help someone else who got stumped like I did. It seems so simple... binding a DataGridView to a List<T>. These are the two general problems that I kept running into: (1) When the data in the list updated, the data on the screen did not update. (2) When I...
20
20286
by: Phil | last post by:
VB2008 I have a DataGridView with MultiSelect = True and SelectionMode=FullRowSelect. One of the columns is a checkbox column. I have a function that goes through all the selected rows and sets the value of this column. For Each row In DataGridView1.SelectedRows row.Cells("MyCheckboxColumn").Value = False Next
2
3927
by: Oleg Subachev | last post by:
I have DataGridView which DataSource is assigned to Table<> object of DataContext connected to SQL Server database. But when the underlying SQL Server database is updated (through ODBC connection) the DataGridView is not updated. I see that Table<is updated because its Count is changed. How to force DataGridView to update itself in such situation ?
0
8000
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,...
0
8495
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, 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...
1
8145
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6815
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, 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...
1
6011
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 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...
0
3960
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...
0
4023
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2474
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1328
bsmnconsultancy
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...

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.