PC Review


Reply
Thread Tools Rating: Thread Rating: 1 votes, 1.00 average.

ASP.NET 2.0 objectdatasource and datakeynames with gridview

 
 
rgparkins
Guest
Posts: n/a
 
      2nd Oct 2007
So, I've bitten the bullet and am converting some of my asp.net 1.1
sites to asp.net 2.0, now after many issues I have come to a stop with
the objectdatasource and gridviews and maybe someone can help!

I have update, add adapter calls on the objectdatasource working well,
however I have an issue with the delete call.

In ASP.NET 2.0 I see that invisible columns are now no longer sent
across in viewstate (something about security) and this was my first
issue when converting, so I read a blog that the way to get round this
is to store the values in the datakeynames property of the grid, ok so
far!

In my gridview I have some dropdown lists in the edittemplate and
checkboxes which DONT store value information therefore things like
"isenabled" column from the database which will be displayed as a
checkbox I store in the datakeynames of the gridview which works fine
apart from when I call the delete method on a row.

My delete method has one parameter, the id of the row and this is
sufficient to delete, BUT because I have placed 3 other columns in the
datakeynames it now requires me to place these columns as parameters
in the delete method!!

I know I can do a workaround of having invisible labels in the
template columns or just create the method with these parameters but
is that really a solution?

Am I missing something, There is only 1 delete parameter in my
objectdatasource markup (see below) so why is it saying I need 4
parameters which cunningly enough is equal to the datakeynames I have
set

If anyone can help or shed some light I would be grateful

Many thanks

Richard

<asp:GridView ID="GridViewDetail" DataSourceID="ObjectDataSource1"
runat="server" AutoGenerateColumns="False"
DataKeyNames="PId,PSpecial,PBillable,PStatus" PageSize="100"
OnRowDataBound="GridViewDetail_RowDataBound" ShowFooter="True"
OnRowCommand="GridViewDetail_RowCommand"
OnRowUpdating="GridViewDetail_RowUpdating"
CssClass="subcostsfullspan">
<Columns>
<Columns.....>
</Columns>
</asp:GridView>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
SelectMethod="GetProducts"

TypeName="xxx.LifeStyleSystem.BusinessLayer.Search.ProductManager"
UpdateMethod="UpdateProduct" DeleteMethod="DeleteProduct">
<UpdateParameters>
<asp:Parameter Name="PId" Type="Int64" />
<asp:Parameter Name="PCostString" Type="String" />
<asp:Parameter Name="PDescription" Type="String" />
<asp:Parameter Name="PGross" Type="Decimal" />
<asp:Parameter Name="PSpecial" Type="Boolean" />
<asp:Parameter Name="PStatus" Type="Int32" />
<asp:Parameter Name="PBillable" Type="Boolean" />
</UpdateParameters>
<DeleteParameters>
<asp:Parameter Name="PdId" Type="Int64" />
</DeleteParameters>
</asp:ObjectDataSource>

 
Reply With Quote
 
 
 
 
wcstow@gmail.com
Guest
Posts: n/a
 
      3rd Oct 2007
Try adding this tho your Deleting method of your datasource.

e.InputParameters.RemoveAt(1)
e.InputParameters.RemoveAt(2)
e.InputParameters.RemoveAt(3)


TP

 
Reply With Quote
 
rgparkins
Guest
Posts: n/a
 
      5th Oct 2007
On 3 Oct, 20:02, wcs...@gmail.com wrote:
> Try adding this tho your Deleting method of your datasource.
>
> e.InputParameters.RemoveAt(1)
> e.InputParameters.RemoveAt(2)
> e.InputParameters.RemoveAt(3)
>
> TP


Many thanks, I placed this in the ObjectDataSource.Deleting event and
actually did this:

e.InputParameters.RemoveAt(1)
e.InputParameters.RemoveAt(2)
e.InputParameters.RemoveAt(3)

because as the parameters are removed it reindexes!

Again many thanks

Richard

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to set Gridview DataKeyNames Property Graphically hon123456 Microsoft ASP .NET 1 24th Jul 2009 09:47 AM
GridView, DataKeyNames Nick Microsoft VB .NET 1 27th Jun 2008 04:35 PM
GridView DataKeyNames rodchar Microsoft ASP .NET 1 1st Feb 2008 08:27 PM
Using gridview datakeynames with muliple keys question needin4mation@gmail.com Microsoft ASP .NET 0 11th Oct 2006 07:34 PM
GridView & DataKeyNames Robert Warnestam Microsoft ASP .NET 0 11th Oct 2004 12:28 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:22 AM.