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

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"
AutoGenerateColumns="False"
style="margin-left: 0px; margin-right: 0px; margin-bottom: 0px"
Width="1020px" BorderColor="Black" BorderStyle="Solid"
CellPadding="4"
BackColor="White" BorderWidth="1px"
ForeColor="Black"
GridLines="Vertical" HorizontalAlign="Center"
BackImageUrl="~/POTracking/images/buttontemplate.jpg"
Font-Names="Calibri" DataSourceID="ObjectDataSource1">
<FooterStyle BackColor="#CCCC99" />
<RowStyle BackColor="#E1E3EC" BorderColor="Black"
BorderStyle="Solid"
BorderWidth="1px" Font-Names="Calibri"
HorizontalAlign="Center" />
<Columns>

<asp:CommandField ButtonType="Image"
DeleteImageUrl="~/POTracking/images/Deletesmall.png"
ShowCancelButton="False" ShowDeleteButton="True"
ShowEditButton="True"
EditImageUrl="~/POTracking/images/Document.png"
ShowInsertButton="True"
UpdateImageUrl="~/POTracking/images/Sync.png" />
<asp:TemplateField HeaderText="QTY"
SortExpression="Quantity">
<headerstyle width="36px" />
<EditItemTemplate>
<asp:TextBox ID="qtybox" runat="server" width="32px"
Text='<%# Bind("Quantity", "{0}")
%>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="qtylbl" runat="server" Text='<%#
Bind("Quantity") %>'></asp:Label>
</ItemTemplate>
<HeaderStyle Width="40px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Bill To"
SortExpression="Billto" >
<headerstyle width="85px" />
<EditItemTemplate>
<asp:DropDownList ID="billtobox" runat="server"
DataSourceID="billto"
DataTextField="name" datavaluefield="id"
Width="79px"
SelectedValue='<%# Bind("Billto", "{0}") %>'
appenddatabounditems="true">
<asp:ListItem Value="0">Select</asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="billto" runat="server"
ConnectionString="<%$
ConnectionStrings:POTracking %>" SelectCommand="billto"
SelectCommandType="StoredProcedure"></asp:SqlDataSource>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="billtolbl"
runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>

<asp:TemplateField HeaderText="Description"
SortExpression="Description">
<headerstyle width="454px" />
<EditItemTemplate>
<asp:TextBox ID="descbox" width="450px"
runat="server" Text='<%# Bind("Description") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="desclbl" runat="server" Text='<%#
Bind("Description") %>'></asp:Label>
</ItemTemplate>

</asp:TemplateField>
<asp:TemplateField HeaderText="Type" SortExpression="Type">
<headerstyle width="44px" />
<EditItemTemplate>
<asp:DropDownList ID="typebox" runat="server"
width="40px" appenddatabounditems="True"
DataSourceID="seltype" DataTextField='typeabbr'
DataValueField="id" SelectedValue='<%#
Bind("Type", "{0}") %>'>
<asp:ListItem Value="0">Select</asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="seltype" runat="server"
ConnectionString="<%$
ConnectionStrings:POTracking %>" SelectCommand="type"
SelectCommandType="StoredProcedure"></asp:SqlDataSource>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="typelbl" runat="server" Text='<%#
Bind("Type") %>'></asp:Label>
</ItemTemplate>
<HeaderStyle Width="46px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Project"
SortExpression="project">
<headerstyle width="110px" />
<EditItemTemplate>
<asp:DropDownList ID="projbox" runat="server"
DataSourceID="Projectrd"
DataTextField="name" DataValueField="Projectid"
width="106px"
SelectedValue='<%# Bind("project", "{0}") %>'
appenddatabounditems="true">
<asp:ListItem Value="0">Select</asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="Projectrd" runat="server"
ConnectionString="<%$
ConnectionStrings:POTracking %>" SelectCommand="proj"
SelectCommandType="StoredProcedure"></asp:SqlDataSource>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="projlbl" runat="server" Text='<%#
Bind("project") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Unit Price"
SortExpression="UnitPrice">
<headerstyle width="79px" />
<EditItemTemplate>
<asp:TextBox ID="unitpricebox" width="75px"
runat="server"
Text='<%# Bind("UnitPrice", "{0:N}") %>'
Height="22px"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="unitpricelbl" runat="server"
Text='<%# Bind("UnitPrice") %>'></asp:Label>
</ItemTemplate>

</asp:TemplateField>
<asp:TemplateField HeaderText="Total"
SortExpression="Total">
<headerstyle width="79px" />
<EditItemTemplate>
<asp:TextBox ID="Totalbox" runat="server"
BackColor="Silver"
BorderColor="Black" Text='<%# Bind("Total",
"{0:N}") %>' ReadOnly="True"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="totallbl" runat="server" Text='<%#
Bind("Total") %>'></asp:Label>
</ItemTemplate>

</asp:TemplateField>
</Columns>
<PagerStyle BackColor="#F7F7DE" ForeColor="Black"
HorizontalAlign="Right" />
<SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True"
ForeColor="White" />
<HeaderStyle Wrap="False" BorderColor="Black"
BorderStyle="Solid"
BorderWidth="1px" />
<AlternatingRowStyle BackColor="#C7C7C7" />
</asp:GridView>

VB.Net Code
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
SelectMethod="AddPOLines" TypeName="POTracker.Purchase_Order"
InsertMethod="AddPOLines"
EnableCaching="True" UpdateMethod="AddPOLines">
<UpdateParameters>
<asp:Parameter Name="Quantity" Type="Int32" />
<asp:Parameter Name="billto" Type="Int32" />
<asp:Parameter Name="description" Type="String" />
<asp:Parameter Name="type" Type="String" />
<asp:Parameter Name="project" Type="Int32" />
<asp:Parameter Name="UnitPrice" Type="Double" />
<asp:Parameter Name="total" Type="Double" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="Quantity" Type="Int32" />
<asp:Parameter Name="billto" Type="Int32" />
<asp:Parameter Name="description" Type="String" />
<asp:Parameter Name="type" Type="String" />
<asp:Parameter Name="project" Type="Int32" />
<asp:Parameter Name="UnitPrice" Type="Double" />
<asp:Parameter Name="total" Type="Double" />
</InsertParameters>
</asp:ObjectDataSource>

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

VB.Net
Imports System.Security
Imports System.Security.Principal.WindowsIdentity
Imports Microsoft.ApplicationBlocks
Partial Public Class create

Inherits System.Web.UI.Page

Private Sub pogrid_RowEditing(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewEditEventArgs) Handles pogrid.RowEditing
pogrid.EditIndex = e.NewEditIndex
End Sub

Private Sub pogrid_RowUpdated(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewUpdatedEventArgs ) Handles
pogrid.RowUpdated
pogrid.EditIndex = -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
ObjectDataSource1.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(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 total As Double) As POLine
Dim newline As POLine = Me.AddPOLines

newline.Quantity = Quantity
newline.Billto = billto
newline.Description = description
newline.Type = type
newline.project = project
newline.UnitPrice = 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.Quantity
' billto = updateln.Billto
' description = updateln.Description
' type = updateln.Type
' project = updateln.project
' UnitPrice = updateln.UnitPrice
' unittotal = updateln.Total
' Return updateln
'End Function

Public Function AddPOLines() As POLine
Dim newline As POLine = New POLine
_polines.Add(newline)
Return newline
End Function
'Public Function upPOLines() As POLine
' Dim updateln As POLine = New POLine
' _polines.Add(updateln)
' 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 1982
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.public.dotnet.framework.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
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...
1
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...
1
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...
0
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...
4
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...
1
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...
2
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....
11
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...
20
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...
2
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.