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.