469,927 Members | 1,904 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,927 developers. It's quick & easy.

ASP.NET 2.0 objectdatasource and datakeynames with gridview

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

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

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

Many thanks


<asp:GridView ID="GridViewDetail" DataSourceID="ObjectDataSource1"
runat="server" AutoGenerateColumns="False"
DataKeyNames="PId,PSpecial,PBillable,PStatus" PageSize="100"
OnRowDataBound="GridViewDetail_RowDataBound" ShowFooter="True"
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"

TypeName="xxx.LifeStyleSystem.BusinessLayer.Search .ProductManager"
UpdateMethod="UpdateProduct" DeleteMethod="DeleteProduct">
<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" />
<asp:Parameter Name="PdId" Type="Int64" />

Oct 2 '07 #1
2 3047
Try adding this tho your Deleting method of your datasource.


Oct 3 '07 #2
On 3 Oct, 20:02, wcs...@gmail.com wrote:
Try adding this tho your Deleting method of your datasource.


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


because as the parameters are removed it reindexes!

Again many thanks


Oct 5 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Ole M | last post: by
4 posts views Thread by Anne Catterick | last post: by
3 posts views Thread by mthomason | last post: by
reply views Thread by Phillip Ian | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.