ASP.NET 2.0 objectdatasource and datakeynames with gridview

R

rgparkins

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>
 
W

wcstow

Try adding this tho your Deleting method of your datasource.

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


TP
 
R

rgparkins

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top