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

Gridview and Updating

Hi Everyone,
I've been having a problem with the Gridview control. I have posted a few
messages relating to the issues, but I have a general question. Does the
Dataview control have to be bound to a datasource that also contains the
update/delete Sql statements? The resaon I ask is that I've done just about
all I can do and can't update the grid. In the RowUpdating event I'm getting
no values in the newvalues or oldvalues vars. I do bind a dataTable that was
produced by a single table stored proc to the datasource property. What am I
missing, I've been working on this problem a little to long, so ANY help
would be great.
Thanks
Mike

Apr 20 '06 #1
5 2225
Hi Michael,

If you were using templates make sure that you are using 2-way databinding
expression such as Bind, otherwise, start from a blue print of a code that
works and build on it. Here are some starting demos:
http://www.asp.net/QuickStart/aspnet...spx#twowaybind
http://www.webswapp.com/codesamples/.../gridview.aspx
http://www.webswapp.com/codesamples/...s/default.aspx

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Michael" wrote:
Hi Everyone,
I've been having a problem with the Gridview control. I have posted a few
messages relating to the issues, but I have a general question. Does the
Dataview control have to be bound to a datasource that also contains the
update/delete Sql statements? The resaon I ask is that I've done just about
all I can do and can't update the grid. In the RowUpdating event I'm getting
no values in the newvalues or oldvalues vars. I do bind a dataTable that was
produced by a single table stored proc to the datasource property. What am I
missing, I've been working on this problem a little to long, so ANY help
would be great.
Thanks
Mike

Apr 20 '06 #2
Hi Phillip,
Thank you so much for the reply. After looking over your suggested reading
and reading some other posts I got the impression that the Edit/Delete
functions only work when you are using a Datasource attached to the
DatasourceId property. Is this correct? Based on that, I have redesigned the
for some using a SqlDataSource attached to the DatasourceId. But I'm getting
the following error when trying to update a row:
Procedure or function Admin_UpdatePOItem has too many arguments specified.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Procedure or function
Admin_UpdatePOItem has too many arguments specified.
Source Error:
An unhandled exception was generated during the execution of the current web
request. Information regarding the origin and location of the exception can
be identified using the exception stack trace below.

Now, I have setup the gridview as follows:
<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" DataSourceID="PODetailDataSource">
<FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />
<Columns>
<asp:BoundField DataField="ItemID" HeaderText="Item ID"
Visible="False" />
<asp:BoundField DataField="POrderId" HeaderText="PO Id"
Visible="False" />
<asp:BoundField DataField="Page" HeaderText="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">
<ItemStyle Width="250px" />
</asp:BoundField>
<asp:BoundField DataField="Qty" HeaderText="Qty">
<ItemStyle HorizontalAlign="Right" />
</asp:BoundField>
<asp:BoundField DataField="UnitPrice"
DataFormatString="{0:C}" HeaderText="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>
And the datasource is as follows:
<asp:SqlDataSource ID="PODetailDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:PODetailsConnectionString %>"
SelectCommand="admin_GetPODetails"
SelectCommandType="StoredProcedure" DeleteCommand="Admin_DeletePOItem"
DeleteCommandType="StoredProcedure" InsertCommand="Admin_AddPOItems"
InsertCommandType="StoredProcedure" UpdateCommand="Admin_UpdatePOItem"
UpdateCommandType="StoredProcedure">
<SelectParameters>
<asp:ControlParameter ControlID="cmbPORequests"
Name="POrderId" PropertyName="SelectedValue"
Type="Int32" />
</SelectParameters>
<DeleteParameters>
<asp:Parameter Name="ItemId" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="ItemID" Type="Int32" />
<asp:Parameter Name="CatalogId" Type="String" />
<asp:Parameter Name="ItemDescription" Type="String" />
<asp:Parameter Name="Qty" Type="Int32" />
<asp:Parameter Name="UnitPrice" Type="Decimal" />
<asp:Parameter Name="Page" Type="String" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="POrderId" Type="Int32" />
<asp:Parameter Name="CatalogeId" Type="String" />
<asp:Parameter Name="ItemDescription" Type="String" />
<asp:Parameter Name="Qty" Type="Int32" />
<asp:Parameter Name="UnitPrice" Type="Decimal" />
<asp:Parameter Name="Page" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
The Stored proc is written as follows:
CREATE PROCEDURE [dbo].[Admin_UpdatePOItem]
@ItemID int,
@CatalogId varchar(20),
@ItemDescription varchar(250),
@Qty int,
@UnitPrice money,
@Page varchar(10)
AS

Update OrderItems Set
CatalogId = @CatalogId,
ItemDescription = @ItemDescription,
Qty = @Qty,
UnitPrice = @UnitPrice,
Page = @Page
Where ItemID = @ItemID
GO

The research that I've done so far I have found that there is an extra
parameter, so I setup a function to remove the parameter but I still get the
error. Here is the code to delete.
'Serves to tell me what parameters and delete the extra one.
Protected Sub PODetailDataSource_Updating(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.SqlDataSourceCommandEven tArgs) Handles
PODetailDataSource.Updating
Dim param As DbParameter
Dim DeleteParam as DbParameter
Debug.WriteLine("Starting Test")
Debug.WriteLine("The command has " & e.Command.Parameters.Count.ToString
& " parameters altogether.")
For Each param In e.Command.Parameters
if param.ParameterName.ToString = "@POrderId" then
DeleteParam = param
End If
if param.ParameterName.ToString.Length > 1 then
Debug.WriteLine("parameter " & param.ParameterName.ToString & "
=> " & (param.Value.ToString & "") & "<br>")
end if
Next
if not isnothing(DeleteParam) then
e.Command.Parameters.Remove(DeleteParam)
end if
Debug.WriteLine("Starting Second Test")
Debug.WriteLine("The command has " & e.Command.Parameters.Count.ToString
& " parameters altogether.")
For Each param In e.Command.Parameters
if param.ParameterName.ToString = "@POrderId" then
DeleteParam = param
End If
if param.ParameterName.ToString.Length > 1 then
Debug.WriteLine("parameter " & param.ParameterName.ToString & "
=> " & (param.Value.ToString & "") & "<br>")
end if
Next
End Sub
After the code is run (before deleting the parameter) I get the following
parameter:
The command has 8 parameters altogether.
parameter @CatalogId => 254-547<br>
parameter @ItemDescription => Testing<br>
parameter @Qty => 5<br>
parameter @UnitPrice => 24.1500<br>
parameter @Page => 55<br>
parameter @ItemId => 3<br>
parameter @POrderId => 1<br> ****Param to remove *****
Starting Second Test
The command has 7 parameters altogether.
parameter @CatalogId => 254-547<br>
parameter @ItemDescription => Testing<br>
parameter @Qty => 5<br>
parameter @UnitPrice => 24.1500<br>
parameter @Page => 55<br>
parameter @ItemId => 3<br>
Sorry for the long message, but I figured you may need to know this info.
What do you think. Thanks for the help.
Michael

Apr 21 '06 #3
Hi Phillip,
I've been testing and researching further. I actually was setting the
DataKeyNames property as follows:

Dim lKeys as String() = {"ItemId", "POrderId"}
grdPOs.DataKeyNames = lKeys

When I removed the POrderId value the POrderId didn't show up in the debug
output, but still getting the same error. If I look at the number of
parameters that printed out, that number is the same the stored proc. I'm
alittle confused. What the heck is going on here. Thanks
Michael

"Phillip Williams" wrote:
Hi Michael,

If you were using templates make sure that you are using 2-way databinding
expression such as Bind, otherwise, start from a blue print of a code that
works and build on it. Here are some starting demos:
http://www.asp.net/QuickStart/aspnet...spx#twowaybind
http://www.webswapp.com/codesamples/.../gridview.aspx
http://www.webswapp.com/codesamples/...s/default.aspx

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Michael" wrote:
Hi Everyone,
I've been having a problem with the Gridview control. I have posted a few
messages relating to the issues, but I have a general question. Does the
Dataview control have to be bound to a datasource that also contains the
update/delete Sql statements? The resaon I ask is that I've done just about
all I can do and can't update the grid. In the RowUpdating event I'm getting
no values in the newvalues or oldvalues vars. I do bind a dataTable that was
produced by a single table stored proc to the datasource property. What am I
missing, I've been working on this problem a little to long, so ANY help
would be great.
Thanks
Mike

Apr 21 '06 #4
Hi Again,
One more thing. Based on my stored proc and parameters I should have only 6
parameters, but the PODetailDataSource_Updating events reports 7 parameters
and after tracing it down I have a "@" as on of the parametername. WHY? That
would be the extra and its not suppose to be there. Have any ideas.
Thanks
Michael
"Phillip Williams" wrote:
Hi Michael,

If you were using templates make sure that you are using 2-way databinding
expression such as Bind, otherwise, start from a blue print of a code that
works and build on it. Here are some starting demos:
http://www.asp.net/QuickStart/aspnet...spx#twowaybind
http://www.webswapp.com/codesamples/.../gridview.aspx
http://www.webswapp.com/codesamples/...s/default.aspx

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Michael" wrote:
Hi Everyone,
I've been having a problem with the Gridview control. I have posted a few
messages relating to the issues, but I have a general question. Does the
Dataview control have to be bound to a datasource that also contains the
update/delete Sql statements? The resaon I ask is that I've done just about
all I can do and can't update the grid. In the RowUpdating event I'm getting
no values in the newvalues or oldvalues vars. I do bind a dataTable that was
produced by a single table stored proc to the datasource property. What am I
missing, I've been working on this problem a little to long, so ANY help
would be great.
Thanks
Mike

Apr 21 '06 #5
Hi Again,
Just wanted to let you know that I have it working, but I still had to catch
the "@" parameter and delete it from the list. I still don't know why that
one was there, if you do, please let me know. But at least its working now.
By the way, I should not have to worry about some other out of the blue
parameter that I will have to delete later, right?
Thanks again Phillip for pointing me in the right direction.
Michael

Apr 21 '06 #6

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

Similar topics

1
by: P | last post by:
Hello, I am having a difficult time updating a record via a stored procedure using the gridview and sqldatasource. I cannot seem to be able to find a way to set everything up so that I can pass...
3
by: | last post by:
Hello, I have created an ASP.NET 2.0 application that utilized a Gridview Control to display and update/delete data. The problem I am having is that the gridview control is displaying the data...
8
by: Mike Kelly | last post by:
I've chosen to implement the "optimistic concurrency" model in my application. To assist in that, I've added a ROWVERSION (TIMESTAMP) column to my main tables. I read the value of the column in my...
5
by: Brian McClellan | last post by:
Just wondering if anyone has a simple example of creating a gridview completely programmatically, i'm not doing anything terribly sophisticated. When creating the gridview declaratively evertying...
0
by: Michael Kellogg | last post by:
I have a problem wherein a query that updates a GridView doesn't seem to really stay in sync with a label I have above the GridView. I have a GridView object that I'm updating with information...
1
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...
11
by: SAL | last post by:
Hello, I have a Gridview control (.net 2.0) that I'm having trouble getting the Update button to fire any kind of event or preforming the update. The datatable is based on a join so I don't know...
0
by: steve | last post by:
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...
0
by: BizWeb | last post by:
Hi, i am new to ASP.NET. I have write a very simple code to try the updating of the GridView but it is not updating the data. Below is the simple code that i have use. <%@ Page Language="vb"...
2
by: xMetalDetectorx | last post by:
Hi Everyone, I have a very simple web app that uses .Net 2.0 login control to authenticate users and allow access to an "admin" folder. Inside that admin folder I have one page that has a...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: 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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...

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.