This is a migrated thread and some comments may be shown as answers.

Radgrid NeedDataSource UpdateCommand

2 Answers 220 Views
Grid
This is a migrated thread and some comments may be shown as answers.
iReplicate
Top achievements
Rank 1
iReplicate asked on 07 Nov 2009, 02:06 AM
I load a radgrid from a system.web.security.MembershipUserCollection.
 
 Protected Sub RadGrid1_NeedDataSource(ByVal source As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource 
        Dim mc As MembershipUserCollection 
        mc = Membership.GetAllUsers 
        RadGrid1.DataSource = mc 
End Sub 
This works fine. When i edit a row i get event Radgrid_UpdateCommand .
I need the dataitem for the row which should be the of type MemberShipUser
so i can update it using Membership.UpdateUser( dataitem)

The e.item.dataitem is nothing.

The grid also does not show the update after the UpdateCommand is done.

Any ideas on how I can do this?


2 Answers, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 09 Nov 2009, 07:12 AM
Hello iReplicate,

DataItem has meaning only in the context of ItemDataBound event. If you are performing manual update operation you should use one of the following approaches demonstrated bellow:

http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/extractvalues/defaultcs.aspx
http://www.telerik.com/help/aspnet-ajax/grdinsertupdatedeleteatdatabaselevel.html

Regards,
Nikolay
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
iReplicate
Top achievements
Rank 1
answered on 09 Nov 2009, 06:43 PM
Thanks Nikolay
The first link was most helpfull.
The key was the line of code that returned the PK value.
FYI Membership is from Membership and Roles
Here's what worked if anyone is interested
 Protected Sub RadGrid1_UpdateCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.UpdateCommand 
        Dim mu As MembershipUser 
        Dim g As Telerik.Web.UI.GridEditableItem 
        Dim newvalues As New Hashtable 
        Dim UserName As String 
 
        g = CType(e.Item, Telerik.Web.UI.GridEditableItem) 
        UserName = g.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("UserName") 
        mu = Membership.GetUser(UserName) 
        e.Item.OwnerTableView.ExtractValuesFromItem(newvalues, g) 
 
        g.UpdateValues(e.Item) 
         
        mu.Email = newvalues.Item("Email").ToString 
        mu.Comment = newvalues.Item("Comment").ToString 
        mu.IsApproved = newvalues.Item("IsApproved") 
        Membership.UpdateUser(mu) 

Tags
Grid
Asked by
iReplicate
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
iReplicate
Top achievements
Rank 1
Share this question
or