Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesUpdating problemsUpdating problems
Previous
 
Next
New Post
12/16/2010 8:14 AM
 
Hi,

I want to add a user to a roll when a checkbox is checked.  I dont know what i'm missin in my code? could any1 have a quick at it
code :

Dim Company As String
    Dim cSQL As String
    Dim cb As CheckBox
    Dim dgi As DataGridItem
    Dim idList As String = ""
    Dim DataRow As Object
    Dim DataSet As Object
    Dim Algemeen As String
    Dim rowindex As Integer
    Dim columnindex As Integer

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim userInfo As UserInfo
        userInfo = UserController.GetCurrentUserInfo()

        If userInfo.UserID = -1 Then

        End If

        Company = userInfo.Profile.GetPropertyValue("Company")

        Dim strSQLconnection As String = ("Data Source=.\SQLExpress;Initial Catalog=dnn2;User ID=vb1;Password=Klompsrv1")

        cSQL = "SELECT Users.UserID, Users.Username, UserProfile.PropertyValue FROM ProfilePropertyDefinition INNER JOIN UserProfile ON ProfilePropertyDefinition.PropertyDefinitionID = UserProfile.PropertyDefinitionID INNER JOIN Users ON UserProfile.UserID = Users.UserID WHERE (ProfilePropertyDefinition.PropertyName = 'Company') AND (UserProfile.PropertyValue = '" + Company + "')"

        Dim sqlConnection As New SqlConnection(strSQLconnection)
        Dim sqlCommand As New SqlCommand(cSQL, sqlConnection)
        Dim SqlAdapter As New SqlDataAdapter(sqlCommand)
        Dim DataSet As New DataSet()
        SqlAdapter.Fill(DataSet)

        If sqlConnection.State = ConnectionState.Closed Then
            sqlConnection.Open()
        End If

        WebDataGrid1.DataSource = DataSet
        WebDataGrid1.DataBind()

    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnEditPermissions.Click

        For i As Integer = 0 To WebDataGrid1.Rows.Count - 1
            For x As Integer = 0 To WebDataGrid1.Columns.Count - 1

                If DirectCast(WebDataGrid1.Rows(i).Items(x).FindControl("Algemeen"), CheckBox).Checked() Then

                    Dim rc As New DotNetNuke.Security.Roles.RoleController()

                    Dim groupName As String = "Algemeen"
                    Dim ri As DotNetNuke.Security.Roles.RoleInfo = rc.GetRoleByName(Me.PortalId, groupName)
                    Dim ui As DotNetNuke.Entities.Users.UserInfo = DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo()
                    rc.AddUserRole(Me.PortalId, ui.UserID, ri.RoleID, Null.NullDate)

                    Dim CurUser As DotNetNuke.Entities.Users.UserInfo = DotNetNuke.Entities.Users.UserController.GetUser(PortalId, UserId, False)
                    DotNetNuke.Entities.Users.UserController.UpdateUser(PortalId, CurUser)

                End If

                If DirectCast(WebDataGrid1.Rows(i).Items(x).FindControl("Financieel"), CheckBox).Checked() Then

                    Dim rc As New DotNetNuke.Security.Roles.RoleController()

                    Dim groupName As String = "Financieel"
                    Dim ri As DotNetNuke.Security.Roles.RoleInfo = rc.GetRoleByName(Me.PortalId, groupName)
                    Dim ui As DotNetNuke.Entities.Users.UserInfo = DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo()
                    rc.AddUserRole(Me.PortalId, ui.UserID, ri.RoleID, Null.NullDate)

                End If

                If DirectCast(WebDataGrid1.Rows(i).Items(x).FindControl("Licentie"), CheckBox).Checked() Then

                    Dim rc As New DotNetNuke.Security.Roles.RoleController()

                    Dim groupName As String = "Licentie"
                    Dim ri As DotNetNuke.Security.Roles.RoleInfo = rc.GetRoleByName(Me.PortalId, groupName)
                    Dim ui As DotNetNuke.Entities.Users.UserInfo = DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo()
                    rc.AddUserRole(Me.PortalId, ui.UserID, ri.RoleID, Null.NullDate)


                End If

                If DirectCast(WebDataGrid1.Rows(i).Items(x).FindControl("Applicatie"), CheckBox).Checked() Then

                    Dim rc As New DotNetNuke.Security.Roles.RoleController()

                    Dim groupName As String = "Applicatie"
                    Dim ri As DotNetNuke.Security.Roles.RoleInfo = rc.GetRoleByName(Me.PortalId, groupName)
                    Dim ui As DotNetNuke.Entities.Users.UserInfo = DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo()
                    rc.AddUserRole(Me.PortalId, ui.UserID, ri.RoleID, Null.NullDate)

                End If

                If DirectCast(WebDataGrid1.Rows(i).Items(x).FindControl("UitDienst"), CheckBox).Checked() Then

                    Dim rc As New DotNetNuke.Security.Roles.RoleController()

                    Dim groupName As String = "UitDienst"
                    Dim ri As DotNetNuke.Security.Roles.RoleInfo = rc.GetRoleByName(Me.PortalId, groupName)
                    Dim ui As DotNetNuke.Entities.Users.UserInfo = DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo()
                    rc.AddUserRole(Me.PortalId, ui.UserID, ri.RoleID, Null.NullDate)

                End If

            Next
        Next

    End Sub
 
New Post
12/16/2010 11:31 AM
 
Are you getting an error anywhere in your code?  You are using the role controller, which is the proper method.

-Mitchel Sellers
Microsoft MVP, ASPInsider, DNN MVP
CEO/Director of Development - IowaComputerGurus Inc.
LinkedIn Profile

Visit mitchelsellers.com for my mostly DNN Blog and support forum.

Visit IowaComputerGurus.com for free DNN Modules, DNN Performance Tips, DNN Consulting Quotes, and DNN Technical Support Services
 
New Post
12/17/2010 3:54 AM
 
Hi Mitchel,
Yes i;m getting an error

Error =   'A critical error has occurred.  Object reference not set to an instance of an object.'

Assuming I forgot something/ did something not in the correct  way something, but cant firgure
 
New Post
12/17/2010 8:28 AM
 
I would suggest checking Admin --> Event Viewer for additional information about the null reference error you are seeing. Of particular use in isolating the error to a section of your code will be the stack trace information.

You could also set a breakpoint at the top of the section of code that is causing the error then stepping through each line of code as it executes using the debugging capabilties of Visual Studio, etc.

I would suspect the error to be occurring in statements such as the following:

If DirectCast(WebDataGrid1.Rows(i).Items(x).FindControl("Applicatie"), CheckBox).Checked()

Note that for each item of each row, FindControl will return a null reference for all columns except the one which contains the desired checkbox. When FindControl returns a null reference, you cannot cast it to a CheckBox - hence the null reference error. Also, this is a very inefficient way of iterating through the role checkboxes.

[Forum Moderator's Note: I have deleted your recent post to a different forum concerning this same issue as it makes following replies more difficult and is against forum policy to post the same question to multiple forums.]

Bill, WESNet Designs
Team Lead - DotNetNuke Gallery Module Project (Not Actively Being Developed)
Extensions Forge Projects . . .
Current: UserExport, ContentDeJour, ePrayer, DNN NewsTicker, By Invitation
Coming Soon: FRBO-For Rent By Owner
 
New Post
12/17/2010 8:54 AM
 
Hi Will,

noticing you saying that my method is inefficient of iterating through the role checkboxes,
How would u recommend me doing it then?

Since the thing is, every the profileproperty of a user gets added with the same property as the others he will be added to the datagrid.
Imo I thought this was the best way of doing it.
 
Previous
 
Next
HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesUpdating problemsUpdating problems


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out