Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / October 2007

Tip: Looking for answers? Try searching our database.

ASP.NET 2.0 objectdatasource and datakeynames with gridview

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
rgparkins - 02 Oct 2007 11:07 GMT
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>
wcstow@gmail.com - 03 Oct 2007 20:02 GMT
Try adding this tho your Deleting method of your datasource.

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

TP
rgparkins - 05 Oct 2007 11:54 GMT
> Try adding this tho your Deleting method of your datasource.
>
[quoted text clipped - 3 lines]
>
> 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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.