473,741 Members | 4,089 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 4279

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

Similar topics

3
2404
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
1409
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
5397
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
18085
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
2651
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
4697
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
3623
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
1807
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
1076
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
8970
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
8794
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
9484
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
9272
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
9211
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6757
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
4826
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2751
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2195
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.