473,570 Members | 2,990 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 4252

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

Similar topics

3
2397
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 =...
0
1403
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
5385
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...
8
18072
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...
5
2637
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...
1
4687
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
3617
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...
4
1793
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>...
3
1070
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
7732
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...
0
7638
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...
0
7956
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. ...
0
8152
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...
0
5247
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3684
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...
1
2136
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
1
1238
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
974
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...

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.