Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Gridview Newvalues are empy after editing

Status
Not open for further replies.

mlee1steph

Programmer
May 23, 2004
73
US
Hi
I'm having a problem getting the newvalues or oldvalues from the RowUpdating
event. I have the following code for the event(See note):
Protected Sub grdPOs_RowUpdating(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles grdPOs.RowUpdating
Dim records(e.NewValues.Count - 1) As DictionaryEntry
Dim entry As DictionaryEntry
Dim DataKeyId as DataKey
try
Dim Itm as New POItem
'Copy the new values into the fields
e.NewValues.CopyTo(records, 0)
''*******************
'Please note, that at this point there is no values in records
''*******************
For Each entry In records
e.NewValues(entry.Key) = Server.HtmlEncode(entry.Value.ToString())
Next
DataKeyId = grdPOs.DataKeys(e.RowIndex )
Itm.POId = DataKeyId("ItemId")
Itm.CatalogNumber = DataKeyId("CatalogId")
Itm.Description = DataKeyId("ItemDescription")
Itm.Qty = DataKeyId("Qty")
Itm.UnitPrice = DataKeyId("UnitPrice")
Itm.Page = DataKeyId("Page")
dim b as Boolean = Utilities.RowUpdating( Itm)
grdPOs.EditIndex = -1
BindData(pUserId)
Catch ex As Exception
msgbox("Error in POAdminEditor.grdPOs_RowUpdating: " & ex.Message )
End Try
End Sub

I use the following function to Bind the grid:
Private sub BindGrid(poOrderid as Integer )
try
'load the data and return a DataTable
Dim dt as DataTable = Utilities.BindGrid(poOrderid)
'Set the datasource
grdPOs.DataSource = dt
grdPOs.DataBind
Catch ex As Exception
msgbox("Error in POAdminEditor.BindGrid: " & ex.Message )
Finally
End Try
End Sub

I can't seem to find a solution in current posts, so I'm hoping someone can
help. Thank you much.
Michael
 
Just wanted to post the markup for the gridview, to see if this helps. I've seen post mention that if the fields are not databound, there will not be any Oldvalues or newvalues generated, but as you can see, I've got most of the fields bound:
<asp:GridView ID="grdPOs" runat="server" AllowPaging="True" AutoGenerateColumns="False"
BackColor="White" BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px"
CellPadding="4" DataKeyNames="ItemId" Height="68px" PageSize="5" Width="642px" AutoGenerateDeleteButton="True" AutoGenerateEditButton="True" AutoGenerateSelectButton="True">
<FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />
<Columns>
<asp:BoundField DataField="ItemID" HeaderText="Item ID" SortExpression="ItemID"
Visible="False" />
<asp:BoundField DataField="POrderId" HeaderText="PO Id"
SortExpression="POrderId" Visible="False" />
<asp:BoundField DataField="Page" HeaderText="Page" SortExpression="Page">
<ItemStyle HorizontalAlign="Right" />
</asp:BoundField>
<asp:BoundField DataField="CatalogId" HeaderText="Catalog #">
<ItemStyle HorizontalAlign="Right" Width="80px" />
</asp:BoundField>
<asp:BoundField DataField="ItemDescription" HeaderText="Description" SortExpression="ItemDescription">
<ItemStyle Width="250px" />
</asp:BoundField>
<asp:BoundField DataField="Qty" HeaderText="Qty" SortExpression="Qty">
<ItemStyle HorizontalAlign="Right" />
</asp:BoundField>
<asp:BoundField DataField="UnitPrice" DataFormatString="{0:C}" HeaderText="UnitPrice"
SortExpression="UnitPrice">
<ItemStyle HorizontalAlign="Right" Width="70px" />
</asp:BoundField>
<asp:BoundField DataFormatString="{0:0.00}" HeaderText="Total" InsertVisible="False" />
</Columns>
<RowStyle BackColor="White" ForeColor="#330099" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399" />
<PagerStyle BackColor="#FFFFCC" ForeColor="#330099" HorizontalAlign="Center" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="#FFFFCC" />
</asp:GridView>

Thanks again for any help.
Michael
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top