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

Help Setting a GridDropDownListColumnEditor Style In Code Behind

2 Answers 125 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Terry
Top achievements
Rank 1
Terry asked on 05 Feb 2012, 07:22 AM
Hi there-

I am struggling to figure out how to do this task. I have a RadGrid with several bound GridDropDownColumns and am trying to do some server side validation when a user clicks Edit to check if the current value is valid. Since these rows may not match a good value, I want to highlight the border of the cell when it is invalid, even though the default behavior of GridDropDownColumns selects a default value when none is given.

Here is the page code:
<telerik:RadGrid ID="RadGrid1" GridLines="None" runat="server" CssClass="AutoShrink"
           AllowPaging="True" AllowAutomaticUpdates="True" PagerStyle-AlwaysVisible='true'
            AutoGenerateColumns="False"
           DataSourceID="AutoInventory_OUStaging_DataSource" OnItemUpdated="RadGrid1_ItemUpdated"
            OnItemDeleted="RadGrid1_ItemDeleted"
           OnItemInserted="RadGrid1_ItemInserted" OnDataBound="RadGrid1_DataBound" OnItemDataBound="RadGrid1_ItemDataBound"
           AllowAutomaticDeletes="True" AllowAutomaticInserts="True" Skin="Sunset"
           AllowSorting="True" PageSize="15">

Here is the code behind:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    if (e.Item is GridEditableItem && e.Item.IsInEditMode)
    {
 
        GridEditableItem item = e.Item as GridEditableItem;
        GridEditManager editMan = item.EditManager;
        GridDropDownListColumnEditor editor = (GridDropDownListColumnEditor)(editMan.GetColumnEditor("DataCenterCode"));
        //DropDownList ddList = editor.DropDownListControl;
 
        editor.DropDownStyle.BorderColor = Color.Red;
        editor.DropDownStyle.BorderStyle = BorderStyle.Solid;
 
        //ddList.Items[0].Attributes["style"] = "color: red";
 
        // item["DataCenterCode"].BorderColor = Color.Red;
        //item["DataCenterCode"].CssClass = "invalidfield";
        //item["DataCenterCode"].ControlStyle.BorderColor = Color.Red;
        //// We can get the id of the edit record by
 
        //GridEditManager editMan = item.EditManager;
 
        //GridDropDownListColumnEditor editor = editMan.GetColumnEditor("DataCenterCode") as GridDropDownListColumnEditor;
        //editor.DropDownStyle.BorderColor = Color.Red;
 
        //list.BorderColor = Color.Red;
 
        //GridDataItem item = (GridDataItem)e.Item;
        //Literal litrl = (Literal)item["DataCenterCode"].Controls[0];  
 
 
        //int updateId = Convert.ToInt32(item.GetDataKeyValue("ServerId"));
        // now write code for binding row data in the interface
 
    }
}

as you can see I have tried many options but haven't been able to get the behavior I desire. I am looking to have the same styling as if I were to set the ItemStyle-BorderColor="RED" on the object like this:
<telerik:GridDropDownColumn DataField="DataCenterCode" DataSourceID="SqlDataSource_DataCenters"
                           HeaderText="DataCenterCode" ListTextField="Acronym" ListValueField="Acronym"
                           UniqueName="DataCenterCode" ColumnEditorID="GridDropDownColumnEditor2" ItemStyle-BorderColor="Red">
                     </telerik:GridDropDownColumn>

how can i accomplish this?

thanks for any help!

2 Answers, 1 is accepted

Sort by
0
Terry
Top achievements
Rank 1
answered on 07 Feb 2012, 12:14 AM
i'm still stuck on this.

can anybody help?
0
Andrey
Telerik team
answered on 09 Feb 2012, 10:10 AM
Hi,

You could try the following code:

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridEditableItem && e.Item.IsInEditMode)
    {
        GridEditFormItem editForm = e.Item as GridEditFormItem;
        RadComboBox comboBox = editForm["DataCenterCode"].Controls[0] as RadComboBox;
        if(some condition is met)
        {           
            comboBox.CssClass = "Invalid";
        }
        else
        {
            comboBox.CssClass = "Normal";
        }
    }
}

and the respective CSS classes:

div.Invalid
{
    border: 1px solid Red;
}
div.Normal
{
     
}

You should change the GridEditFormItem to GridDataItem if you are using InPlace edit mode and RadComboBox with DropDownList you have set this control to render.

Give this approach a try and check whether this is the desired behavior.

Regards,
Andrey
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Tags
Grid
Asked by
Terry
Top achievements
Rank 1
Answers by
Terry
Top achievements
Rank 1
Andrey
Telerik team
Share this question
or