473,687 Members | 3,536 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Updating GridView with RowUpdating but still need to defineUpdateMet hod on ObjectdataSourc e?

I have been fighting with trying to update a GridView for a while. I
don't want to use the "built-in" way to do it because I am using
business layer methods for updating and deleteing and I don't want to
have my parameter names in those methods have to be
"original_Param etername" or even if I change the
OldValuesParame terFormatString to get rid of the "original" I would
still have just "Parametername" . I think most people user parameters
like sParametername or iParametername name to help define the type of
the parameter. They typically don't follow the exact name of the
database column name....and they especially don't have "original_"
tacked on the fron of them....anyway. ...

So I am using RowEditing, RowUpdating on the GridView so I can use my
business layer method and send the parameters as I want. Now the
problem is I get an exception stating that I need to specify the
UpdateMethod on the ObjectDataSourc e. If I am manually handling these
events why do I need to specify the UpdateMethod?

So I play along and specify the UpdateMethod and put in my business
layer method. Now it performs the update, but still throws the
exception "could not find a non-generic method 'AddUpWaveHeigh t' that
has parameters: Height, ID". This is of course because my parameters
are sHeight and sID, not Height and ID.

So I can work around this by cancelling the ObjectdataSourc e_Updating
method in the codebehind.

But this seems like a workaround to me. I would like to know if this
is the correct behavior and the correct way to do this or if I am
missing something. I don't want to move forward until I have a good
feeling of how this is supposed to work and that I can make it work
the way I woudl like it to.

Any help is appreciated. Below is my page code and codebehind:

---------------------
PAGE CODE
---------------------

<asp:ObjectData Source ID="odsWaveHeig ht" runat="server"
OldValuesParame terFormatString ="{0}" SelectMethod="d sWaveHeightList "
UpdateMethod="A ddUpWaveHeight"
TypeName="FindM yBoardLibrary.C Selector">
<SelectParamete rs>
<asp:Paramete r Name="sRiderSki llID" DefaultValue="0 "
Type="String" />
</SelectParameter s>
</asp:ObjectDataS ource>
<asp:GridView ID="GridView1" runat="server"
DataSourceID="o dsWaveHeight" AutoGenerateCol umns="False"
DataKeyNames="I D"
OnRowEditing="G ridView1_RowEdi ting"
OnRowCancelingE dit="GridView1_ RowCancelingEdi t"
OnRowUpdating=" GridView1_RowUp dating"
OnRowDeleting=" GridView1_RowDe leting">
<Columns>
<asp:TemplateFi eld>
<EditItemTempla te>
<asp:LinkButt on ID="lbtUpdate" runat="server"
CausesValidatio n="True" CommandName="Up date" Text="Update"></
asp:LinkButton>
<asp:LinkButt on ID="lbtCancel" runat="server"
CausesValidatio n="False" CommandName="Ca ncel" Text="Cancel"></
asp:LinkButton>
</EditItemTemplat e>
<ItemTemplate >
<asp:LinkButt on ID="lbtEdit" runat="server"
CausesValidatio n="False" CommandName="Ed it" Text="Edit"></
asp:LinkButton>
</ItemTemplate>
</asp:TemplateFie ld>
<asp:TemplateFi eld SortExpression= "Height"
HeaderText="Hei ght">
<EditItemTempla te>
<asp:TextBox ID="txtHeight" Runat="server" Text='<
%# Bind("Height") %>'></asp:TextBox>
<asp:RequiredFi eldValidator ID="rfvHeight"
Runat="server" ErrorMessage="Y ou must enter the Height"
ControlToValida te="txtHeight"> </asp:RequiredFie ldValidator>
</EditItemTemplat e>
<ItemTemplate >
<asp:Label ID="lblHeight" Runat="server" Text='<%#
Bind("Height") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateFie ld>
<asp:TemplateFi eld>
<ItemTemplate >
<asp:LinkButt on ID="lbtDelete" runat="server"
CausesValidatio n="False" CommandName="De lete" Text="Delete"></
asp:LinkButton>
</ItemTemplate>
</asp:TemplateFie ld>
</Columns>
</asp:GridView>

---------------------
CODEBEHIND
---------------------

Protected Sub GridView1_RowCa ncelingEdit(ByV al sender As Object,
ByVal e As System.Web.UI.W ebControls.Grid ViewCancelEditE ventArgs)
Handles GridView1.RowCa ncelingEdit

GridView1.EditI ndex = -1
GridView1.DataB ind()

End Sub

Protected Sub GridView1_RowDe leting(ByVal sender As Object, ByVal
e As System.Web.UI.W ebControls.Grid ViewDeleteEvent Args) Handles
GridView1.RowDe leting

Dim cSelector As New CSelector

Dim sID As String =
GridView1.DataK eys(e.RowIndex) .Values(0).ToSt ring

cSelector.Delet eWaveHeight("0" , sID)
GridView1.DataB ind()

End Sub

Protected Sub GridView1_RowEd iting(ByVal sender As Object, ByVal e
As System.Web.UI.W ebControls.Grid ViewEditEventAr gs) Handles
GridView1.RowEd iting

GridView1.EditI ndex = e.NewEditIndex
GridView1.DataB ind()

End Sub

Protected Sub GridView1_RowUp dating(ByVal sender As Object, ByVal
e As System.Web.UI.W ebControls.Grid ViewUpdateEvent Args) Handles
GridView1.RowUp dating

Dim cSelector As New CSelector

Dim sID As String =
GridView1.DataK eys(e.RowIndex) .Values(0).ToSt ring
Dim txtHeight As TextBox =
CType(GridView1 .Rows.Item(e.Ro wIndex).FindCon trol("txtHeight "),
TextBox)
Dim sHeight As String = txtHeight.Text

cSelector.AddUp WaveHeight("0", sID, sHeight)

GridView1.EditI ndex = -1
GridView1.DataB ind()

End Sub

Private Sub odsWaveHeight_U pdating(ByVal sender As Object, ByVal e
As System.Web.UI.W ebControls.Obje ctDataSourceMet hodEventArgs) Handles
odsWaveHeight.U pdating

e.Cancel = True

End Sub
Aug 20 '08 #1
0 4272

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

Similar topics

3
2401
by: Amelyan | last post by:
I seem to have a problem using VS2005 GridView. When I tried to implement RowUpdating or RowUpdated handlers NewValues, OldValues, and AllKeys collecitons are empty. Also, when I tried to implement RowDeleting, Values collection is empty. I load my grid by executing my stored procedure that returns DataSet. grid.DataSource = GetMyItems(); grid.BindData(); Does anyone have an example of working with GridView?
0
1406
by: loga123 | last post by:
Hi All, I am using asp.net 2.0. I have a gridview with AutoGenerateEditButton="True" . I am trying to access newValues in rowupdating event. It gives me "oldvalues" collection. I have a) datakeynames property set b) I am using template fields in my gridview and have "EVAL" for ItemTemplate and "BIND" for EditItemTemplate
5
5393
by: BenG | last post by:
Hi. I have a gridview control on a web form (asp.net 2.0) that's bound to a objectDataSource. The objectdatasource which is bound to a class I've written in the DAL to read and update the database. The grid contains three columns - an ID (GUID), a name (string) and a rowversion (timestamp), and the data is passed to/from the page in an instance of a data entity object. When I open the page the grid loads properly, but if I attempt to edit...
8
18081
by: Greg Lyles | last post by:
Hi all, I'm trying to develop an ASP.NET 2.0 website and am running into some real problems with what I thought would be a relatively simple thing to do. In a nutshell, I'm stuck on trying to display data in a "GridView" which is tied to an "ObjectDataSource". In turn, this ObjectDatasource gets it's data from a strongly-typed business object within my code.
5
2647
by: Randy Smith | last post by:
Hi ALL, I wonder if anyone has been using n-tier to bind to a GridView control by using the ObjectDataSource. This is our first OOP web application, and we have no tables. Right now we are simply working with objects in memory. So, it appears as though Microsoft requires that our datamapper classes reside inside a folder called "App_Code", and NO WHERE ELSE. So, has anyone successfully been able to place their datamappers in a...
1
4695
by: =?Utf-8?B?Q2hyaXM=?= | last post by:
Hi, I have a gridview which I added a <asp:CommandField EditText="E" CancelText="C" UpdateText="U" ButtonType="Link" ShowEditButton="True" /> my gridview looks like this <asp:GridView ID="GridView1" runat="server" OnRowEditing="RowEdit" OnRowCancelingEdit="RowCancel" OnRowUpdating="RowUpdating"...
1
3621
by: ist | last post by:
Hi, I am trying to create a Session-Wide, Disconnected, Updatable DataTable (or DataSet) object and use it through an ASP.NET GridView. The scenario is this: 1. When the page is first loaded, connect to DB, get data, fill DataTable. 2. Bind DataTable to GridView. Set DataTable as a Session object. 3. User continues navigating page, but after first load, no more DB
4
1804
by: Jonathan Wood | last post by:
Greetings, I have a GridView control. For a couple of reasons, I ended up with a TemplateField to contain my Edit and Delete links, something like this: <asp:TemplateField ShowHeader="False"> <EditItemTemplate> <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Update" Text="Update"></asp:LinkButton> &nbsp;<asp:LinkButton ID="LinkButton2" runat="server"
3
1073
by: Cralis | last post by:
Hi guys, I am new to GridViews.. I have a gridview that displays 3 columns. Description, MahUsed and a calculated % Used field. When I click Edit on the row, the MahUsed goes into Edit mode, and I can change the value. Now the problems start.
0
8590
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9070
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...
0
8947
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 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...
0
7621
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...
0
4321
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
4543
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2964
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
2
2214
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1948
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.