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

Change text color in modified cell

3 Answers 264 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Raul
Top achievements
Rank 1
Raul asked on 09 Dec 2013, 02:28 PM
Hi Good morning,

I have a RadGrid on edit mode, I need change the color when a cell is modified, Could you please confirm me if would be possible implement that functionality and How?

Thanks in advance,

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 10 Dec 2013, 03:41 AM
Hi Raul,

Please try the following code snippet:

C#:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
    if (e.Item is GridEditableItem && e.Item.IsInEditMode)
    {
        GridEditableItem item = (GridEditableItem)e.Item;
        foreach (GridColumn column in item.OwnerTableView.Columns)
        {
            if (column.ColumnType == "GridBoundColumn")
            {
                TextBox txt = (TextBox)item[column.UniqueName].Controls[0];
                txt.AutoPostBack = true;
                txt.TextChanged += new EventHandler(txt_TextChanged);
            }
            if (column.ColumnType == "GridNumericColumn")
            {
                RadNumericTextBox txtnumeric = (RadNumericTextBox)item[column.UniqueName].Controls[0];
                txtnumeric.AutoPostBack = true;
                txtnumeric.TextChanged += new EventHandler(txtnumeric_TextChanged);
            }
        }
    
}
void txtnumeric_TextChanged(object sender, EventArgs e)
{
    RadNumericTextBox txt = (RadNumericTextBox)sender;
    txt.BackColor = Color.Gold;
}
 
void txt_TextChanged(object sender, EventArgs e)
{
    TextBox txt = (TextBox)sender;
    txt.BackColor = Color.Gold;
}

Thanks,
Princy
0
Raul
Top achievements
Rank 1
answered on 10 Dec 2013, 05:25 PM
Hi Princy,

Thank you for you reply, but, the Text Change event is not firing, My  grid is in EditMode = "Batch",

In fact I have more questions (Obviously, I am a new using Telerik controls),

I expect click on a cell and the cell change to be editable, (as EditMode="Batch" I got that behavior), I added a template column (aspx code below) due that I need to add a RadTooltip (in order to display the previous - current value of that cell),

Now when I click on a cell the RadNumericTextBox is empty (I expect to see current value on the RadNumbericTextBox)  and the value that I entry dissapear once I left the cell,

*I am populating the grid from a Dataset using the NeedDataSource event,

if you have questions, please let me know,

Best Regards,

 

<telerik:GridTemplateColumn HeaderText="Jan" HeaderStyle-Width="75px" SortExpression="Jan" UniqueName="Jan" DataField="Jan">

<ItemTemplate>

<asp:Label ID="lbl" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Jan")%>'></asp:Label>

<telerik:RadToolTip ID="RadToolTip1" runat="server" TargetControlID="lbl" RelativeTo="Element" Position="BottomCenter" RenderInPageRoot="true">

<%

# DataBinder.Eval(Container, "DataItem.Account")%>

-

<%

# DataBinder.Eval(Container, "DataItem.Jan")%>

-

% Current value on the cell, I dont know How reference that field here%

</telerik:RadToolTip>

</ItemTemplate>

<EditItemTemplate>

 

<telerik:RadNumericTextBox ID="txtJan" runat="server"></telerik:RadNumericTextBox>

 

</EditItemTemplate>

 

</telerik:GridTemplateColumn>


0
Angel Petrov
Telerik team
answered on 12 Dec 2013, 12:42 PM
Hello Raul,

In order to change the edited cell background color you can modify the .rgBatchChanged class. For example
.rgBatchChanged
         {
             background-color:red;
         }
will change the background to red once a cell is edited.

As for the second issue it is caused by the fact that a tool tip is placed inside the ItemTempale of the grid. In complex scenarios like these the grid does not know from which control it should extract the value(whether from the label or tool tip). In order to make things work you can subscribed to the four batch edit events(OnBatchEditGetCellValue,OnBatchEditSetCellValue,OnBatchEditGetEditorValue,OnBatchEditSetEditorValue) and handle things manually like demonstrated in this help article.

Regards,
Angel Petrov
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Grid
Asked by
Raul
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Raul
Top achievements
Rank 1
Angel Petrov
Telerik team
Share this question
or