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

AutomaticDeletes on an ODS without keys?

2 Answers 57 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mark H
Top achievements
Rank 1
Mark H asked on 02 Jul 2009, 10:53 PM
I am putting together a simple interface to allow Membership (Roles and Users) data to be managed.

I have an ODS which hooks into the GetAllRoles() method of the Roles provider which simply returns string [] containing each rolename.

I want to then allow roles to be deleted from the system using the automatic capabilities of the radgrid but cannot seem to get this to work. AFAICT there is no DayaKeyNames value to use for the string array which, if I autogenerate the columns at runtime is simply called "Item". I've created teh columns manually, a GridButtonColumn for the delete and a Rolename column. I have the DeleteMethod and DeleteParameters specified correctly in the ODS but nothing I do seems to get the value of the rolename passed to the ODS when I hit Delete. What do I need to do to get this value communicated properly? ALternatively what do I need to do to manually process the delete?

M

2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 03 Jul 2009, 09:01 AM
Hi,


A solution would be to use an ArrayList object for Telerik RadGrid structure generation.
You can use the following ArrayList  GetRoles to populate the grid. Create a Class UserRole  with a property RoleName and pass the values from the string array  as shown below. Now you will be able to bind a column using the field RoleName and set the DataKeyName accordingly
 
 
public class Class1 
     
    static string connectionstring = "SetConnectionString"
        SqlConnection conn = new SqlConnection(connectionstring); 
        SqlCommand cmd = new SqlCommand(); 
 
     
    public ArrayList GetRoles() 
    { 
        ArrayList list = new ArrayList(); 
        string[] strlist = Roles.GetAllRoles(); 
        foreach (String str in strlist) 
        { 
            list.Add(new UserRole(str)); 
        } 
        return list; 
    } 
 
    public void DeleteRole(string RoleName) 
    { 
        Roles.DeleteRole(RoleName); 
    } 
 
public class UserRole 
    private string _rolename; 
    public UserRole( string rolename) 
    { 
        _rolename = rolename; 
    } 
   
    public string RoleName 
    { 
        get 
        { 
            return _rolename; 
        } 
        set 
        { 
            value = _rolename
        } 
    } 
 
 

You can set the ObjectDataSource accordingly

        <asp:ObjectDataSource ID="ObjectDataSource1"  TypeName="Class1" DeleteMethod="DeleteRole" SelectMethod="GetRoles" runat="server" >
         <DeleteParameters >
       <asp:Parameter Name="RoleName" />
        </DeleteParameters>
        </asp:ObjectDataSource>

Thanks,
Shinu
0
Mark H
Top achievements
Rank 1
answered on 03 Jul 2009, 09:05 AM
Thanks - I figured it might be necessary to create an intermediate class. It's pity because it would be tider to be able to use the Membership system directly and this does work with Users/Membership where there is a key field :(

Mark
Tags
Grid
Asked by
Mark H
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Mark H
Top achievements
Rank 1
Share this question
or