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

Change Row Color on RadGrid ItemCommand Event

2 Answers 422 Views
Grid
This is a migrated thread and some comments may be shown as answers.
thecruciable
Top achievements
Rank 1
thecruciable asked on 31 Mar 2010, 04:06 PM
Hello,

I have looked at several threads here on how to change row color but none seems to fit my requirement. I have a Rad grid that has GridEditCommandColumn and which has the ability to Update the records. My questions is how do I change the color of a row after a successful update. I am using Rad grid Item Command event to update my records:

Here is my code

ASPX:

<telerik:RadGrid runat="server" ID="rgGridResults" GridLines="None" Skin="BallState"
                AllowSorting="true" AllowPaging="true" AllowFilteringByColumn="true" AutoGenerateColumns="false"
                ShowGroupPanel="false" ShowFooter="true"
                OnNeedDataSource="rgGridResults_NeedDataSource"
                OnItemDataBound="rgGridResults_ItemDataBound"
                OnItemCommand="rgGridResults_ItemCommand">
                <ValidationSettings EnableValidation="true" ValidationGroup="vgGrid" />
                <MasterTableView EditMode="InPlace" DataKeyNames="donorid">
                    <Columns>
                        <telerik:GridEditCommandColumn ButtonType="LinkButton" EditText="Edit" UpdateText="Update"
                            CancelText="Cancel" />
                        <telerik:GridBoundColumn HeaderText="Donor Name" DataField="name" SortExpression="name"
                            ReadOnly="true" />
                        <telerik:GridBoundColumn HeaderText="Donor ID" DataField="donorid" SortExpression="donorid"
                            ReadOnly="true" />
                        <telerik:GridBoundColumn HeaderText="Spouse ID" DataField="relttnid" SortExpression="relttnid"
                            ReadOnly="true" />
                        <telerik:GridBoundColumn HeaderText="Gift ID" DataField="giftid" SortExpression="giftid"
                            ReadOnly="true" />
                        <telerik:GridBoundColumn HeaderText="Pledge ID" DataField="pledgeid" SortExpression="pledgeid"
                            ReadOnly="true" />
                        <telerik:GridBoundColumn HeaderText="Credit Date" DataField="credtdat" SortExpression="credtdat"
                            ReadOnly="true" />
                        <telerik:GridBoundColumn HeaderText="Type" DataField="trantype" SortExpression="trantype"
                            ReadOnly="true" />
                        <telerik:GridBoundColumn HeaderText="Legal Amount" DataField="legal_credit" SortExpression="legal_credit"
                            ReadOnly="true" />
                        <telerik:GridBoundColumn HeaderText="Soft Credit Amount" DataField="legal_credit"
                            SortExpression="legal_credit" ReadOnly="true" />
                        <telerik:GridBoundColumn HeaderText="Soft Credit Amount" DataField="soft_credit"
                            SortExpression="soft_credit" ReadOnly="true" />
                        <telerik:GridBoundColumn HeaderText="Fund" DataField="fundnum" SortExpression="fundnum"
                            ReadOnly="true" />
                        <telerik:GridBoundColumn HeaderText="Fund Name" DataField="fundname" SortExpression="fundname"
                            ReadOnly="true" />
                        <telerik:GridBoundColumn HeaderText="System Review Code" DataField="needs_review_code"
                            SortExpression="needs_review_code" ReadOnly="true" />
                        <telerik:GridBoundColumn HeaderText="System Review Comment" DataField="needs_review_comment"
                            SortExpression="needs_review_comment" ReadOnly="true" />
                       
                        <telerik:GridTemplateColumn HeaderText="Encumbered Amount" DataField="match_eligible_amount"
                            SortExpression="match_eligible_amount" ReadOnly="true">
                            <ItemTemplate>
                                <asp:Label runat="server" ID="lblEncumberedAmount" />
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridTemplateColumn HeaderText="Disbursed Amount" DataField="disburse_amount"
                            SortExpression="disburse_amount" ReadOnly="true">
                            <ItemTemplate>
                                <asp:Label runat="server" ID="lblDisbursedAmount" />
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridBoundColumn HeaderText="Disbursed Date" DataField="disburse_date" SortExpression="disburse_date"
                            ReadOnly="true" />
                        <telerik:GridTemplateColumn HeaderText="Household Max" DataField="household_maximum_amt"
                            SortExpression="household_maximum_amt">
                            <ItemTemplate>
                                <asp:Label runat="server" ID="lblHouseholdMax" />
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                    </Columns>
                </MasterTableView>
            </telerik:RadGrid>

C# code:

protected void rgGridResults_ItemCommand(object sender, GridCommandEventArgs e)
        {
            GridDataItem gdiItem = e.Item as GridDataItem;

            if (gdiItem != null)
            {
                if (e.Item.IsInEditMode)
                {
                    switch (e.CommandName)
                    {
                        case "Update":
                            Page.Validate("vgGrid");

                            if (Page.IsValid)
                            {                                
                                int intDonorID;

                                if (int.TryParse(e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["donorid"].ToString(), out intDonorID))
                                {
                                    e.Item.CssClass = "RowColor";
                                   /* Data.Registered.Update(intGradID, intConfYear, tbxBadgeName.Text, rbtnlNotAttendingBsu.SelectedValue, rbtnlRsvp.SelectedValue,
                                                           rbtnlOffCampus.SelectedValue, rbtnlTeaching.SelectedValue, rbtnlResearch.SelectedValue, rbtnlLab.SelectedValue,
                                                           rbtnlOther.SelectedValue);

                                    //Call this method to update the total after the update is sucessfully completed.
                                    GetGridTotals();
                                    rgRegistered.Rebind();*/
                                }
                            }
                            else
                            {
                                rgGridResults.Controls.Add(new LiteralControl(string.Format("<span class=\"ErrorText\">There was an error updating the record.</span>")));
                            }
                            break;
                    }
                }
            }
        }

Kindly let me know a work around for this..

Thanks..

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 01 Apr 2010, 07:27 AM
Hi,

I used variable to save the index of last updated row and tried setting the BackColor for the row (based on index saved) in PreRender event. Here is the code that I tried.

C#:
 
    public int index = -1; 
    protected void RadGrid1_UpdateCommand(object source, GridCommandEventArgs e) 
    { 
        GridEditFormItem editForm = (GridEditFormItem)e.Item; // I used EditMode as EditForm 
        GridDataItem item = (GridDataItem)editForm.ParentItem; 
        index = item.ItemIndex;  
    } 
    protected void RadGrid1_PreRender(object sender, EventArgs e) 
    { 
        if (index >= 0) 
        { 
            RadGrid1.MasterTableView.Items[index].BackColor = System.Drawing.Color.Red; 
        } 
    } 

Thanks,
Princy.
0
thecruciable
Top achievements
Rank 1
answered on 05 Apr 2010, 06:38 PM
Hi Princy,

I tried your example did not work for me.. Is there an another workaround.

Thanks
Tags
Grid
Asked by
thecruciable
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
thecruciable
Top achievements
Rank 1
Share this question
or