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

Changing Edit Form Background AFTER update

0 Answers 36 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Amy
Top achievements
Rank 1
Amy asked on 24 Apr 2017, 07:42 PM

Hello,

I'm using a RadGrid to update some info and would like to have a part of the Edit Form change background color as a user prompt after an update operation is performed.

The grid uses the NeedDataSource event
The grid uses Edit Form templates
The grid uses the OnUpdateCommand to do manual updates
The Edit Form Template has three divs to display information in three columns, and I would optimally like one of the three to change background color after the update is successfully performed.

I have found that using the ItemDataBound event and formatting using IsPostBack works, but that also updates the background color just on opening the edit form, which I obviously don't want. Do I need to do this on the client side? Do I need to add a querystring, session, or other hidden parameter to pass to check for a successful update? Or am I missing something simple that will check this for me?

Grid and UpdateCommand code:

    <telerik:RadGrid ID="RadGrid1" runat="server" AllowSorting="True" OnNeedDataSource="RadGrid1_NeedDataSource"
        IsExporting="False" AutoGenerateColumns="False" OnItemDataBound="RadGrid1_ItemDataBound"  
         OnItemCreated="RadGrid1_ItemCreated" OnUpdateCommand="RadGrid1_UpdateCommand"  
        >
        <MasterTableView Name="Requests" DataKeyNames="RequestID" EditMode="EditForms" >   
            <NoRecordsTemplate>
                No Requests right now!
            </NoRecordsTemplate>

        <RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column"></RowIndicatorColumn>
        <ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column"></ExpandCollapseColumn>

        <Columns>
        <telerik:GridEditCommandColumn></telerik:GridEditCommandColumn>
             <telerik:GridBoundColumn DataField="RequestID" 
                FilterControlAltText="Filter RequestID column" HeaderText="Request ID" 
                SortExpression="RequestID" UniqueName="RequestID" Visible="false">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="StudentUID" 
                FilterControlAltText="Filter StudentUID column" HeaderText="StudentUID" 
                SortExpression="StudentUID" UniqueName="StudentUID" Visible="false">
            </telerik:GridBoundColumn>
            <telerik:GridTemplateColumn HeaderText="Name" UniqueName="StudentName" Visible="true">
            <ItemTemplate>
                <asp:Label ID="lblStudentName" runat="server" Text='<%# Bind("LastName") %>' />, <asp:Label ID="lblStudentFName" runat="server" Text='<%# Bind("FirstName") %> '></asp:Label>
            </ItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridBoundColumn DataField="Campus" 
                FilterControlAltText="Filter Campus column" HeaderText="Campus" 
                SortExpression="Campus" UniqueName="Campus">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="AcphsEmail" 
                FilterControlAltText="Filter AcphsEmail column" HeaderText="AcphsEmail" 
                SortExpression="AcphsEmail" UniqueName="AcphsEmail">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="YearOrProgram" 
                FilterControlAltText="Filter YearOrProgram column" HeaderText="Program Year" 
                SortExpression="YearOrProgram" UniqueName="YearOrProgram">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="MeetingName" 
                FilterControlAltText="Filter MeetingName column" HeaderText="Meeting Name" 
                SortExpression="MeetingName" UniqueName="MeetingName">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="ReimbursementType" 
                FilterControlAltText="Filter ReimbursementType column" 
                HeaderText="Type" SortExpression="ReimbursementType" 
                UniqueName="ReimbursementType">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="TotalRequested" DataType="System.Decimal" 
                FilterControlAltText="Filter TotalRequested column" HeaderText="Amt Requested" 
                SortExpression="TotalRequested" UniqueName="TotalRequested" DataFormatString="{0:C}">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="DateSubmitted" DataType="System.DateTime" 
                FilterControlAltText="Filter DateSubmitted column" HeaderText="Submitted" 
                SortExpression="DateSubmitted" UniqueName="DateSubmitted">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="RequestStatus" 
                FilterControlAltText="Filter Status column" HeaderText="Status" 
                SortExpression="RequestStatus" UniqueName="RequestStatus">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="AmountApproved" DataType="System.Decimal" 
                FilterControlAltText="Filter AmountApproved column" HeaderText="Amt Approved" 
                SortExpression="AmountApproved" UniqueName="AmountApproved" DataFormatString="{0:C}">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="NotifiedOfApproval" 
                FilterControlAltText="Filter NotifiedOfApproval column" 
                HeaderText="Notified?" SortExpression="NotifiedOfApproval" 
                UniqueName="NotifiedOfApproval">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="AmountReimbursed" DataType="System.Decimal" 
                FilterControlAltText="Filter AmountReimbursed column" 
                HeaderText="Amt Reimbursed" SortExpression="AmountReimbursed" 
                UniqueName="AmountReimbursed" DataFormatString="{0:C}">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="HasAttachments" HeaderText="Attachments" AllowFiltering="false">
            </telerik:GridBoundColumn>
        </Columns>
    
        <EditFormSettings EditFormType="Template">
        <FormTemplate>
        <div class="container">
        <div class="column-left"> <%--Request Details--%>
        <p>Request Details</p>
        <asp:Label ForeColor="White" Name="RequestID" ID="Label1" runat="server" Text='<%# Bind("RequestID") %>'></asp:Label><br />
        <asp:Label Name="lblAcphsEmail" ID="lblAcphsEmail" runat="server" Text='<%# Bind("AcphsEmail") %>' Visible="false"></asp:Label><br />
            Status: <asp:Label ID="lblStatus" runat="server" Text='<%# Bind("RequestStatus") %>'>
            </asp:Label><br />
    
            Meeting Name: <asp:Label ID="lblMeetingName" runat="server" Text='<%# Bind("MeetingName") %>'>
            </asp:Label><br />

            Reimbursement Type: <asp:Label ID="lblReimbursementType" runat="server" Text='<%# Bind("ReimbursementType") %>'>
            </asp:Label><br />

            Registration Fee: <asp:Label ID="lblRegFee" runat="server" Text='<%# String.IsNullOrEmpty(Eval("RegFee").ToString()) || Eval("RegFee").ToString() == "0.0000" ? "n/a" : string.Format("{0:C}", Eval("RegFee")) %>'>
            </asp:Label><br />

            Transportation Fee: <asp:Label ID="lblTranspoFee" runat="server" Text='<%# String.IsNullOrEmpty(Eval("TranspoFee").ToString()) || Eval("TranspoFee").ToString() == "0.0000" ? "n/a" : string.Format("{0:C}", Eval("TranspoFee")) %>'>
            </asp:Label><br />

            Hotel Fee: <asp:Label ID="lblHotelFee" runat="server" Text='<%# String.IsNullOrEmpty(Eval("HotelFee").ToString()) || Eval("HotelFee").ToString() == "0.0000" ? "n/a" : string.Format("{0:C}", Eval("HotelFee")) %>'>
            </asp:Label><br />

            Poster Printing Fees/Charges (if applicable): <asp:Label ID="lblPosterFee" runat="server" Text='<%# String.IsNullOrEmpty(Eval("PosterFee").ToString()) || Eval("PosterFee").ToString() == "0.0000" ? "n/a" : string.Format("{0:C}", Eval("PosterFee")) %>'></asp:Label><br />

            Additional Info: <asp:Label ID="lblAdditionalInfo" runat="server" Text='<%# Bind("AdditionalInfo") %>'>
            </asp:Label><br />

            Date Submitted: <asp:Label ID="lblDateSubmitted" runat="server" Text='<%# Bind("DateSubmitted") %>'>
            </asp:Label><br />

            Total Amount Requested: <asp:Label ID="lblTotalRequested" runat="server" Text='<%# string.Format("{0:C}", Eval("TotalRequested")) %>'>
            </asp:Label><br />
            <div style="background-color:Wheat">
            Amount Approved: $<asp:Label ID="Label2" runat="server" Text='<%# String.IsNullOrEmpty(Eval("AmountApproved").ToString()) || Eval("AmountApproved").ToString() == "0.0000" ? "" : string.Format("{0:C}", Eval("AmountApproved")) %>'></asp:Label></div><br />
        
        </div>
        <div class="column-center">
            <p>Approval Actions</p>
            <asp:Label ForeColor="White" Name="RequestID" ID="lblRequestID" runat="server" Text='<%# Bind("RequestID") %>'></asp:Label><br />
            Status:<asp:DropDownList ID="ddlStatus" runat="server" SelectedValue='<%# Bind("RequestStatus") %>'
                DataSource='<%# (new string[] { "Received", "Pending", "Approved", "Declined" }) %>' 
                AppendDataBoundItems="True">
                    <asp:ListItem Selected="True" Text="Select..." Value=""></asp:ListItem>
            </asp:DropDownList><br />
    
            Pre-Approval:<asp:DropDownList ID="ddlPreApproval" runat="server" SelectedValue='<%# Bind("PreApprovalStatus") %>'
                DataSource='<%# (new string[] { "Under Review", "Pending Final Approval", "Incomplete", "Approved", "Declined" }) %>'
                AppendDataBoundItems="True">
                    <asp:ListItem Selected="True" Text="Select..." Value=""></asp:ListItem>
            </asp:DropDownList><br />

            Pre-Approval By: <asp:TextBox ID="txtPreApprovedBy" runat="server" Text='<%#Bind("PreApprovedBy")%>' ></asp:TextBox><span id="dam_return"><asp:LinkButton id="Button1" runat="server" OnClientClick="GetValue();" text="Carla" ></asp:LinkButton><%--<a href="#" onclick="javascript:return AccessOnClient()">Carla</a></span> onclientclick="return AccessOnclient();" --%><br />

            Pre-Approval Date: <asp:TextBox ID="txtPreApprovalDate" runat="server" Text='<%#Bind("PreApprovalDate")%>'></asp:TextBox><br />

            Notes (shared in email???): <asp:TextBox ID="txtApprovalNotes" runat="server" Text='<%#Bind("PreApprovalNotes") %>' TextMode="MultiLine" Rows="5" Columns="10"></asp:TextBox><br />

            Final Approval Required? <telerik:RadButton ID="IsTrue" runat="server" ButtonType="ToggleButton" ToggleType="CheckBox"
            Checked='<%# (DataBinder.Eval(Container.DataItem,"FinalApprovalRequired") is DBNull ?false:DataBinder.Eval(Container.DataItem,"FinalApprovalRequired")) %>'>
            <ToggleStates>
                <telerik:RadButtonToggleState Value="True" />
                <telerik:RadButtonToggleState Value="False" />
            </ToggleStates>
        </telerik:RadButton>
        <br />

            Final Approval Status<asp:DropDownList ID="ddlFinalApproval" runat="server" SelectedValue='<%# Bind("FinalApprovalStatus") %>'
                DataSource='<%# (new string[] { "N/A", "Under Review", "Approved", "Declined" }) %>' 
                AppendDataBoundItems="True">
                    <asp:ListItem Selected="True" Text="Select..." Value=""></asp:ListItem>
            </asp:DropDownList><br />

            Final Approval By: <asp:TextBox ID="txtFinalApprovalBy" runat="server" Text='<%#Bind("FinalApprovalBy")%>'></asp:TextBox><br />

            Final Approval Date: <asp:TextBox ID="txtFinalApprovalDate" runat="server" Text='<%# Bind("FinalApprovalDate") %>' ></asp:TextBox><br />

            Amount Approved: $<telerik:RadNumericTextBox ID="txtAmountApproved" runat="server" Text='<%# Bind("AmountApproved") %>'></telerik:RadNumericTextBox><br />

        <asp:Button ID="btnUpdate" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>' runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'></asp:Button>&nbsp;
        <asp:Button ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False" CommandName="Cancel"></asp:Button>
        </div>
        <div class="column-right">
        <asp:Panel ID="pnlmessages" runat="server">
        <p>Send approprate mail message(s)</p>
        <p>Approved!<a href="#" title="Send Approved Message" onclick="openMailWindow('<%#DataBinder.Eval(Container.DataItem, "RequestID") %>','Approved');return false;"><img style="border:0px;vertical-align:middle;" height="24px" width="24px" alt="RequestMail" src="Images/mail_next.png"/></a>&nbsp;</p>
        <p>Declined<a href="#" title="Send Declined Message" onclick="openMailWindow('<%#DataBinder.Eval(Container.DataItem, "RequestID") %>','Declined');return false;"><img style="border:0px;vertical-align:middle;" height="24px" width="24px" alt="RequestMail" src="Images/mail_next.png"/></a>&nbsp;</p>
        <p>Incomplete<a href="#" title="Send Incomplete Message" onclick="openMailWindow('<%#DataBinder.Eval(Container.DataItem, "RequestID") %>','Incomplete');return false;"><img style="border:0px;vertical-align:middle;" height="24px" width="24px" alt="RequestMail" src="Images/mail_next.png"/></a>&nbsp;</p>
        <p>New, blank message to Requestor<a href="#" title="Send New, Blank Mail" onclick="openMailWindow('<%#DataBinder.Eval(Container.DataItem, "RequestID") %>','Blank');return false;"><img style="border:0px;vertical-align:middle;" height="24px" width="24px" alt="RequestMail" src="Images/mail_next.png"/></a>&nbsp;</p>
        </asp:Panel>
        </div>
        </div>
    </FormTemplate>
        <EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn>
    </EditFormSettings>
    </MasterTableView>

        <FilterMenu EnableImageSprites="False"></FilterMenu>
    </telerik:RadGrid>


    protected void RadGrid1_UpdateCommand(object sender, GridCommandEventArgs e)
    {
        ErrorLog oErrorLog = new ErrorLog();
        GridEditableItem editedItem = e.Item as GridEditableItem;
        
        if (!e.Item.IsInEditMode)//(changedRows.Length != 1)
        {
            lblProblem.Text += "Unable to locate the Request for updating.";
            e.Canceled = true;
            return;
        }
        string savedoldvaluescount = editedItem.SavedOldValues.Count.ToString();
        string ddlPreOld = editedItem.SavedOldValues["PreApprovalStatus"].ToString();
        //Update new values
        Hashtable newValues = new Hashtable();
        newValues["RequestID"] = (editedItem.FindControl("lblRequestID") as Label).Text;
        newValues["AcphsEmail"] = (editedItem.FindControl("lblAcphsEmail") as Label).Text;
        newValues["RequestStatus"] = (editedItem.FindControl("ddlStatus") as DropDownList).SelectedValue;
        newValues["PreApprovalStatus"] = (editedItem.FindControl("ddlPreApproval") as DropDownList).SelectedValue;
        newValues["PreApprovedBy"] = (editedItem.FindControl("txtPreApprovedBy") as TextBox).Text;
        newValues["PreApprovalDate"] = (editedItem.FindControl("txtPreApprovalDate") as TextBox).Text;
        newValues["PreApprovalNotes"] = (editedItem.FindControl("txtApprovalNotes") as TextBox).Text;
        newValues["FinalApprovalRequired"] = (editedItem.FindControl("IsTrue") as RadButton).Value.ToString() == "True" ? true : false;
        newValues["FinalApprovalStatus"] = (editedItem.FindControl("ddlFinalApproval") as DropDownList).SelectedValue;
        newValues["FinalApprovalBy"] = (editedItem.FindControl("txtFinalApprovalBy") as TextBox).Text;
        newValues["FinalApprovalDate"] = (editedItem.FindControl("txtFinalApprovalDate") as TextBox).Text; //Convert.ToDateTime((editedItem.FindControl("txtFinalApprovalDate") as TextBox).Text);
        if (String.IsNullOrEmpty(newValues["FinalApprovalDate"].ToString())) { newValues["FinalApprovalDate"] = DBNull.Value;}
        newValues["AmountApproved"] = String.IsNullOrEmpty((editedItem.FindControl("txtAmountApproved") as RadNumericTextBox).Text.ToString()) ? 0 : Convert.ToDecimal((editedItem.FindControl("txtAmountApproved") as RadNumericTextBox).Text);
        //changedRows[0].BeginEdit();

        try
        {
            //construct the connection
            String strConn = WebConfigurationManager.ConnectionStrings["CAMSConnectionString"].ConnectionString;
            SqlConnection conn = new SqlConnection(strConn);
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;

            //load up the parameters with variable values
            cmd.Parameters.Add("@RequestID",  SqlDbType.Int).Value = newValues["RequestID"];
            cmd.Parameters.Add("@RequestStatus",  SqlDbType.NVarChar).Value = newValues["RequestStatus"];
            cmd.Parameters.Add("@PreApprovalStatus",  SqlDbType.NVarChar).Value = newValues["PreApprovalStatus"];
            cmd.Parameters.Add("@PreApprovedBy",  SqlDbType.NVarChar).Value = newValues["PreApprovedBy"];
            cmd.Parameters.Add("@PreApprovalDate",  SqlDbType.DateTime).Value = newValues["PreApprovalDate"];
            cmd.Parameters.Add("@PreApprovalNotes",  SqlDbType.NVarChar).Value = newValues["PreApprovalNotes"];
            cmd.Parameters.Add("@FinalApprovalRequired",  SqlDbType.Bit).Value = newValues["FinalApprovalRequired"];
            cmd.Parameters.Add("@FinalApprovalStatus",  SqlDbType.NVarChar).Value = newValues["FinalApprovalStatus"];
            cmd.Parameters.Add("@FinalApprovalBy",  SqlDbType.NVarChar).Value = newValues["FinalApprovalBy"];
            cmd.Parameters.Add("@FinalApprovalDate",  SqlDbType.DateTime).Value = newValues["FinalApprovalDate"];
            cmd.Parameters.Add("@AmountApproved",  SqlDbType.Money).Value = newValues["AmountApproved"];

            conn.Open();

            //update the request with new info
            cmd.CommandText = "UPDATE ACPHS_RequestToTravel_Approval SET RequestStatus = @RequestStatus, PreApprovalStatus = @PreApprovalStatus, PreApprovedBy = @PreApprovedBy, PreApprovalDate = @PreApprovalDate, PreApprovalNotes = @PreApprovalNotes, FinalApprovalRequired = @FinalApprovalRequired, FinalApprovalStatus = @FinalApprovalStatus, FinalApprovalBy = @FinalApprovalBy, FinalApprovalDate = @FinalApprovalDate, AmountApproved = @AmountApproved WHERE RequestID = @RequestID";
            cmd.ExecuteNonQuery();
            conn.Close();
            //HERE IS WHERE I WOULD LIKE TO UPDATE THE COLOR. I AM PRODUCING AN ALERT INSTEAD.
   //Panel pnlm = (Panel)e.Item.FindControl("pnlmessages");
            //pnlm.BackColor = System.Drawing.Color.Wheat;
            string scriptstring = "radalert('Remember to send the email!', 330, 210);";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "radalert", scriptstring, true);


            
        }
        catch (Exception ex)
        {
            //changedRows[0].CancelEdit();
            lblProblem.Text += "Unable to update Request. Reason: " + ex.Message;
            oErrorLog.WriteErrorLog(ex.ToString());
            e.Canceled = true;
        }
        
    }

 

Thanks for any suggestions!

Amy

No answers yet. Maybe you can help?

Tags
Grid
Asked by
Amy
Top achievements
Rank 1
Share this question
or