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

Color DropDownList inside RadGrid EditItemTemplate Mode

2 Answers 89 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Jason
Top achievements
Rank 1
Jason asked on 18 Jul 2017, 05:00 PM

Hello,

I have a RadGrid with a DropDownList in its edititem Template area.

I would like to color the items depending on Org Name.

 

Here is the RadGrid definition  (I just removed columns before and after for ease of reading)

<telerik:RadGrid ID="RadExamGrid" runat="server" AutoGenerateColumns="False"
                 AllowSorting="True"  ExportCellFormating="RadExamGrid_ExportCellFormatting"
                 GridLines="Both" EnableViewState="True"
                MasterTableView-AllowSorting="True" PagerStyle-AlwaysVisible="True"
                  PagerStyle-Position="TopAndBottom" ResolvedRenderMode="Classic"
                  OnNeedDataSource="RadExamGrid_NeedDataSource" Skin="Sunset" >
                 <ExportSettings ExportOnlyData="True" FileName="Allocation"
                    HideStructureColumns="True" OpenInNewWindow="True" Excel-FileExtension="xls" Excel-Format="Biff" SuppressColumnDataFormatStrings="True">
                    <Excel Format="Biff" />
                </ExportSettings>
                <MasterTableView AllowPaging="True" PageSize="10" CommandItemDisplay="Top" Caption="Exams Received"
                InsertItemPageIndexAction="ShowItemOnCurrentPage" DataKeyNames="EntryNum" OverrideDataSourceControlSorting="True" CommandItemSettings-ShowExportToExcelButton="True" CommandItemSettings-ShowExportToPdfButton="False" CommandItemSettings-ShowExportToWordButton="True" >
 
                    <Columns>
<%   COLUMNS before not included %>
                    
 
                      <%--Org No Column --%>
                    <telerik:GridTemplateColumn HeaderText="Org Name" SortExpression="OrgName" HeaderStyle-HorizontalAlign="Left" HeaderStyle-Width="250px">
                        <ItemTemplate>
                            <%# DataBinder.Eval(Container.DataItem, "OrgName")%>
                        </ItemTemplate>
                       <EditItemTemplate>     
                            <telerik:RadDropDownList ID="RadddlOrg" runat="server" AutoPostBack="True" Width="300px" DataTextField="OrgName" DataValueField="OrgNo" SelectedValue='<%# DataBinder.Eval(Container.DataItem, "OrgNo")%> ' OnSelectedIndexChanged="RadddlOrg_SelectedIndexChanged" CausesValidation="false">
                            </telerik:RadDropDownList>
                     
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="Field is required" ControlToValidate="RadddlOrg" Display="Static" Font-Bold="True" SetFocusOnError="True" ForeColor="#FF0000"></asp:RequiredFieldValidator>
                        </EditItemTemplate>
                    </telerik:GridTemplateColumn>
 
<%   COLUMNS after not included %>
            
                    </Columns>
 
                    <EditFormSettings EditColumn-ButtonType="PushButton">
                        <EditColumn FilterControlAltText="Filter EditCommandColumn1 column"
                            UniqueName="EditCommandColumn1">
                        </EditColumn>
                    </EditFormSettings>
                </MasterTableView>
                <PagerStyle Position="TopAndBottom" />
            </telerik:RadGrid>

 

 

Here is my RadGrid Item DataBound method.

 

Protected Sub RadExamGrid_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadExamGrid.ItemDataBound
        Dim cmdItem As GridCommandItem = DirectCast(RadExamGrid.MasterTableView.GetItems(GridItemType.CommandItem)(0), GridCommandItem)
        Dim intResult As Integer = 0
 
        If TypeOf e.Item Is GridDataItem Then
            Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)
            Dim btnDelete As ImageButton = DirectCast(item("ReceivedCommand").Controls(0), ImageButton)
            Dim itemValue As String = item.DataItem("RCVDTS")
            If itemValue.Trim = "" Then
                btnDelete.Visible = True
            Else
                btnDelete.Visible = False
            End If
 
        End If
 
        ''want dropdownlist for edit;
        If TypeOf e.Item Is GridEditableItem And e.Item.IsInEditMode Then
            Dim editItem As GridEditFormItem = DirectCast(e.Item, GridEditFormItem)
            Dim drpOrg As Telerik.Web.UI.RadDropDownList = DirectCast(editItem.FindControl("RadddlOrg"), Telerik.Web.UI.RadDropDownList)
            Dim txtStudno As Telerik.Web.UI.RadTextBox = DirectCast(editItem.FindControl("RadtxtStudNo"), Telerik.Web.UI.RadTextBox)
 
            For i = 0 To objEXR.OrgNameDataView.Count - 1
                Dim li As New DropDownListItem
                li.Value = objEXR.OrgNameDataView.Item(i).Item(0)
                li.Text = objEXR.OrgNameDataView.Item(i).Item(1)
                If li.Text.Trim = "4HR CHALLENGER EXAM SESSION" Then
                    li.ForeColor = System.Drawing.Color.Blue
                End If
                drpOrg.Items.Add(li)
            Next
 
            If txtStudno.Text.Trim = "" Then
                txtStudno.Text = "1"
            End If
 
 
        End If
 
 
 
    End Sub

 

I read some articles on RadDropDownList.VisualListItemFormatting Event, but was unsuccessful to implement it.  I went with simple approach to create list item, and then set its forecolor.   Thanks in advance for any help.  

 

2 Answers, 1 is accepted

Sort by
0
Peter Milchev
Telerik team
answered on 24 Jul 2017, 08:28 AM
Hello Jason,

I would suggest using the CssClass property of the item and then styling the item with CSS as recommended in the Change background of specific items forum thread: 

html .rddlSlide .blue-item {
    color: blue;
    background-color: aquamarine;
}

Protected Sub RadExamGrid_ItemDataBound(sender As Object, e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemDataBound
    ''want dropdownlist for edit;
    If TypeOf e.Item Is GridEditableItem And e.Item.IsInEditMode Then
        Dim editItem As GridEditFormItem = DirectCast(e.Item, GridEditFormItem)
        Dim drpOrg As Telerik.Web.UI.RadDropDownList = DirectCast(editItem.FindControl("RadddlOrg"), Telerik.Web.UI.RadDropDownList)
        For i As Integer = 0 To 5
            Dim li As New DropDownListItem()
            li.Value = i.ToString() + "HR CHALLENGER EXAM SESSION"
            li.Text = i.ToString() + "HR CHALLENGER EXAM SESSION
            If li.Text.Trim = "4HR CHALLENGER EXAM SESSION" Then
                li.CssClass = "blue-item"
            End If
            drpOrg.Items.Add(li)
 
        Next
    End If
End Sub

Regards,
Peter Milchev
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Jason
Top achievements
Rank 1
answered on 25 Jul 2017, 10:08 PM

Peter, 

Thank you so much.. that worked !!!

Cheers

 

Tags
DropDownList
Asked by
Jason
Top achievements
Rank 1
Answers by
Peter Milchev
Telerik team
Jason
Top achievements
Rank 1
Share this question
or