SF 5.1 RadGrid problem updating from user control

Posted by Community Admin on 04-Aug-2018 17:40

SF 5.1 RadGrid problem updating from user control

All Replies

Posted by Community Admin on 07-Sep-2012 00:00

Hi I am trying to implement a user control to allow the logged in user to create sub accounts (we have a tightly controlled membership on a support site).  These subaccounts need to be in the form <user-name>-[A CUSTOMER ENTERED NAME]  (e.g., "MYCOMPANY-BACKOFFICE"). The 'parent account can assign several roles and change the password on the 'sub-accounts'.

I have a custom edit form template to accomplish this (see code below) - i cannot get the 'updated' event to fire so that i can assign the roles (and changed the password if needed) - i can read the value of whether they are in a role in the edit template but but it doesn't seem to be working for the grid itself.

Can anyone tell me what I am doing wrong?  I have wasted hours trying to figure this out and i'm sure it's something stupid i'm doing!  Thanks for any help...

Regards,

Steve Ledbetter

=----------------------------------------------------------------------=
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="AddSubUsers.cs" Inherits="_AddSubUsers" ViewStateMode="Enabled" %>


<asp:Button ID="CreateUser" runat="server" Text="Add Sub Account" />
<br />
<br />


<asp:Label ID="LabelUser" runat="server" Text=""></asp:Label>


<telerik:RadGrid ID="GridViewUsers" runat="server" AllowPaging="True" AutoGenerateColumns="False"
    CellSpacing="0" GridLines="None" AutoGenerateDeleteColumn="True" OnNeedDataSource="GridViewUsers_NeedDataSource"
    BorderStyle="None" OnItemDataBound="GridViewUsers_OnItemDataBound" OnUpdateCommand="GridViewUsers_UpdateCommand"
     AutoGenerateEditColumn="true" OnItemEvent="GridViewUsers_ItemEvent" AllowAutomaticUpdates="False"
    OnItemUpdated="GridViewUsers_ItemUpdated"  OnItemCommand="GridviewUsers_OnItemCommand">
    <MasterTableView DataKeyNames="id">
        <Columns>
            <telerik:GridTemplateColumn HeaderText="Secondary Account" UniqueName="user_name"
                HeaderStyle-Font-Bold="true">
                <EditItemTemplate>
                    <table width="400">
                        <tr>
                            <td valign="top">
                                <table>
                                    <tr>
                                        <td align="right" style="width: 100px">
                                            <asp:Label ID="Label1" runat="server" Text="User Name:  " />
                                        </td>
                                        <td align="left">
                                            <asp:Label ID="LabelSubName" Font-Bold="true" runat="server" Text='<%# Eval("user_name") %>' />
                                        </td>
                                    </tr>
                                    <tr>
                                        <td align="right">
                                            <asp:Label ID="Label5" runat="server" Text=' Password:' />
                                        </td>
                                        <td align="left">
                                            <asp:TextBox ID="TextBoxPassword" runat="server" Text="(Unchanged)" Font-Bold="false" />
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                    </table>
                </EditItemTemplate>
                <ItemTemplate>
                    <table>
                        <tr>
                            <td valign="top">
                                <asp:Label ID="Label1" runat="server" Text='User Name:  ' />
                                <asp:Label ID="user_nameLabel" runat="server" Text='<%# Eval("user_name") %>' Font-Bold="true" />
                                <br/>
                                <asp:Label ID="Label2" runat="server" Text='Created on:  ' />
                                <asp:Label ID="creation_dateLabel" runat="server" Text='<%# Eval("creation_date") %>'
                                    Font-Bold="false" />
                                <br/>
                                <asp:Label ID="Label4" runat="server" Text='Last Login:  ' />
                                <asp:Label ID="last_login_dateLabel" runat="server" Text='<%# Eval("last_login_date") %>'
                                    Font-Bold="false" />
                            </td>
                        </tr>
                    </table>
                </ItemTemplate>
                <HeaderStyle Font-Bold="True"></HeaderStyle>
            </telerik:GridTemplateColumn>
            <telerik:GridTemplateColumn HeaderText="Permissions" UniqueName="permissions" HeaderStyle-Font-Bold="true">
                <EditItemTemplate>
                    <table>
                        <tr>
                            <td valign="top">
                                <table>
                                    <tr>
                                        <td align="right" rowspan="3" style="width: 100px">
                                        </td>
                                        <td>
                                            <asp:Label ID="Label6" runat="server" Text="This user can:" />
                                            <br/>
                                            <asp:CheckBox Text=" Get Access Codes" ID="CheckBoxGetAccessCodes" runat="server"
                                                Checked="false" Enabled="true" Font-Bold="false" />
                                            <br/>
                                            <asp:CheckBox Text=" Submit Support Requests" ID="CheckBoxSubmitSupportRequests"
                                                runat="server" Checked="false" Enabled="true" Font-Bold="false" />
                                            <br/>
                                            <asp:CheckBox Text=" Download Program Updates" ID="CheckBoxProgramUPdates" runat="server"
                                                E Checked="false" Enabled="true" Font-Bold="false" />
                                        </td>
                                    </tr>
                                </table>
                            </td>
                            <%--                                
                            <td valign="top">
                                <asp:Button ID="EditUserButton" runat="server" Text="Edit" />
                                <asp:Button ID="ButtonDelete" runat="server" Text="Delete" />
                            </td>
                            --%>
                        </tr>
                    </table>
                </EditItemTemplate>
                <ItemTemplate>
                    <table>
                        <tr>
                            <td valign="top">
                                <asp:CheckBox Text=" Get Access Codes" ID="CheckBoxGetAccessCodes" runat="server"
                                    Checked="false" Enabled="false" Font-Bold="false" />
                                <br>
                                <asp:CheckBox Text=" Submit Support Requests" ID="CheckBoxSubmitSupportRequests"
                                    runat="server" Checked="false" Enabled="false" Font-Bold="false" />
                                <br>
                                <asp:CheckBox Text=" Download Program Updates" ID="CheckBoxProgramUpdates" runat="server"
                                    Checked="false" Enabled="false" Font-Bold="false" />
                            </td>
                            <td valign="top">
                                <%--                                
                                <asp:Button ID="EditUserButton" runat="server" Text="Edit" />
                                <asp:Button ID="ButtonDelete" runat="server" Text="Delete" />
                                --%>
                            </td>
                        </tr>
                    </table>
                </ItemTemplate>
                <HeaderStyle Font-Bold="True"></HeaderStyle>
            </telerik:GridTemplateColumn>


        </Columns>
        <EditFormSettings>
            <EditColumn FilterControlAltText="Filter EditCommandColumn column" ButtonType="PushButton">
            </EditColumn>
        </EditFormSettings>
    </MasterTableView>
    <FilterMenu EnableImageSprites="False">
    </FilterMenu>
</telerik:RadGrid>

=-------------------------------------------------------------------------------=
CODE BEHIND:
=--------------------------------------------------------------------------------=
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Text.RegularExpressions;
using System.ComponentModel;
using Telerik;
using Telerik.Sitefinity;
using Telerik.Sitefinity.Security;
using Telerik.Sitefinity.Security.Model;
using RFMSUtilities;
using System.Data.SqlClient;
using Telerik;
using Telerik.Web.UI;
using Telerik.Web.Data;
using Telerik.Sitefinity.Security;
using Telerik.Sitefinity.Security.Model;


public partial class _AddSubUsers : System.Web.UI.UserControl

    public static DataTable dtTable;
    public static string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["Sitefinity2"].ConnectionString;
    public SqlConnection SqlConnection = new SqlConnection(connectionString);
    public SqlDataAdapter SqlDataAdapter = new SqlDataAdapter();
    public SqlCommand SqlCommand = new SqlCommand();
    public string selectQuery = "";


    public string parentUser = "123";  // FOR TESTING PUEPOSES!!!


    protected void Page_Load(object sender, EventArgs e)
   
        if (!IsPostBack)
       
       
        // parentUser = RFMSUtilities.RFMSUtils.RFMSGetCurrentUserName();
        LabelUser.Text = parentUser;
   




    protected void GridViewUsers_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
   
        dtTable = new DataTable();
        SqlConnection.Open();
        try
       
            selectQuery = "SELECT [user_name], [last_name], [last_modified], [last_login_date], [first_name], [id], [creation_date] FROM [sf_users] WHERE [user_name] LIKE '" + parentUser + "-%'";
            SqlDataAdapter.SelectCommand = new SqlCommand(selectQuery, SqlConnection);
            SqlDataAdapter.Fill(dtTable);
            GridViewUsers.DataSource = dtTable;
       
        finally
       
            SqlConnection.Close();
       
   




    protected void GridViewUsers_OnItemDataBound(object sender, GridItemEventArgs e)
   
        string uName = "";
        string parentName = parentUser;
        if (e.Item is GridDataItem)
       
            GridDataItem dataItem = e.Item as GridDataItem;
            TableCell cellName = dataItem["user_name"];
            uName = (string)cellName.FindControl("user_nameLabel").ToString();
            TableCell cellPermissions = dataItem["permissions"];
            CheckBox accCodes = cellPermissions.FindControl("CheckBoxGetAccessCodes") as CheckBox;
            CheckBox supportIncidents = cellPermissions.FindControl("CheckBoxSubmitSupportRequests") as CheckBox;
            CheckBox programUpdates = cellPermissions.FindControl("CheckBoxProgramUpdates") as CheckBox;
            accCodes.Checked = RFMSUtilities.RFMSUtils.RFMSUserIsInRole(RFMSUtilities.RFMSUtils.RFMSGetUser(uName), RFMSUtilities.RFMSUtils.RFMSGetRoleByName("RFMSAccessCodesUser"));
            supportIncidents.Checked = RFMSUtilities.RFMSUtils.RFMSUserIsInRole(RFMSUtilities.RFMSUtils.RFMSGetUser(uName), RFMSUtilities.RFMSUtils.RFMSGetRoleByName("RFMSSupportIncidentUser"));
            programUpdates.Checked = RFMSUtilities.RFMSUtils.RFMSUserIsInRole(RFMSUtilities.RFMSUtils.RFMSGetUser(uName), RFMSUtilities.RFMSUtils.RFMSGetRoleByName("RFMSFileDownloadUser"));
       


        if ((e.Item is GridEditableItem) && (e.Item.IsInEditMode))
       
            GridEditFormItem editForm = e.Item as GridEditFormItem;
            TextBox pWord = editForm.FindControl("TextBoxPassword") as TextBox;
            pWord.Text = "(Not Changed)";
            Label nameLabel = editForm.FindControl("LabelSubName") as Label;
            uName = nameLabel.Text;
            CheckBox accCodes = editForm.FindControl("CheckBoxGetAccessCodes") as CheckBox;
            CheckBox supportIncidents = editForm.FindControl("CheckBoxSubmitSupportRequests") as CheckBox;
            CheckBox programUpdates = editForm.FindControl("CheckBoxProgramUpdates") as CheckBox;
            accCodes.Checked = RFMSUtilities.RFMSUtils.RFMSUserIsInRole(RFMSUtilities.RFMSUtils.RFMSGetUser(uName), RFMSUtilities.RFMSUtils.RFMSGetRoleByName("RFMSAccessCodesUser"));
            supportIncidents.Checked = RFMSUtilities.RFMSUtils.RFMSUserIsInRole(RFMSUtilities.RFMSUtils.RFMSGetUser(uName), RFMSUtilities.RFMSUtils.RFMSGetRoleByName("RFMSSupportIncidentUser"));
            programUpdates.Checked = RFMSUtilities.RFMSUtils.RFMSUserIsInRole(RFMSUtilities.RFMSUtils.RFMSGetUser(uName), RFMSUtilities.RFMSUtils.RFMSGetRoleByName("RFMSFileDownloadUser"));
       


   




    protected void GridViewUsers_UpdateCommand(object source, GridCommandEventArgs e)
   
        Response.Write("<script language='javascript'>alert('Called OnUPdateCommand.');</script>");
   




    protected void GridViewUsers_ItemUpdated(object sender, GridUpdatedEventArgs e)
   
        Response.Write("<script language='javascript'>alert('Item updated - EDIT.');</script>");
   


    protected void GridViewUsers_ItemEvent(object sender, GridItemEventArgs e)
   
        Response.Write("<script language='javascript'>alert('Item EVENT.');</script>");
        string eve = e.EventInfo.EventName;
        if (eve == "UpdateCommand")
       
            Response.Write("<script language='javascript'>alert('UpdateCommand!');</script>");
       
   


    protected void GridviewUsers_OnItemCommand(object source, GridCommandEventArgs e)
   
        Response.Write("<script language='javascript'>alert('Item command event.');</script>");


        if (e.CommandName == RadGrid.UpdateCommandName)
       
            Response.Write("<script language='javascript'>alert('BAZINGA');</script>");
       


        string tempx = e.CommandName;
   




This thread is closed