Hi,
I have a simple Grid with a GridDropDownColumn using the default RadCombBox. On Eidt and Insert, I bind the Combo to an XML-based Dictionary inside ItemDataBound. Both functionalities are wroking fine and I can save updated records without problems. However, I keep getting above error every time I attempt to Insert, although the process is working, whether I Cancel or Insert, with the Combo being populated as expected. In other words, the error doesn't affect Insertion but it is annoying to keep showing! How can I eliminate it?
Grid markup:
ItemDataBound (VB):
I thought of handling each process separately, but I will end up with redundant code!
Many thanks in advance.
I have a simple Grid with a GridDropDownColumn using the default RadCombBox. On Eidt and Insert, I bind the Combo to an XML-based Dictionary inside ItemDataBound. Both functionalities are wroking fine and I can save updated records without problems. However, I keep getting above error every time I attempt to Insert, although the process is working, whether I Cancel or Insert, with the Combo being populated as expected. In other words, the error doesn't affect Insertion but it is annoying to keep showing! How can I eliminate it?
Grid markup:
<
telerik:RadGrid
ID
=
"CoursesGrid"
runat
=
"server"
Width
=
"920px"
AutoGenerateColumns
=
"False"
PageSize
=
"20"
AllowPaging
=
"True"
CssClass
=
"AddBorders"
>
<
MasterTableView
DataKeyNames
=
"CourseID"
EditMode
=
"EditForms"
CommandItemDisplay
=
"Top"
CommandItemSettings-AddNewRecordText
=
"Add New Course"
InsertItemDisplay
=
"Top"
InsertItemPageIndexAction
=
"ShowItemOnCurrentPage"
EnableNoRecordsTemplate
=
"true"
ShowHeader
=
"true"
>
<
Columns
>
<
telerik:GridEditCommandColumn
UniqueName
=
"EditBtn"
ButtonType
=
"ImageButton"
HeaderStyle-Width
=
"60px"
Resizable
=
"false"
ItemStyle-HorizontalAlign
=
"Center"
></
telerik:GridEditCommandColumn
>
<
telerik:GridBoundColumn
UniqueName
=
"CourseID"
DataField
=
"CourseID"
HeaderText
=
"Course ID"
ColumnEditorID
=
"CourseIDEditor"
HeaderStyle-Width
=
"70px"
Resizable
=
"false"
ItemStyle-HorizontalAlign
=
"Center"
></
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
UniqueName
=
"CourseName"
DataField
=
"CourseName"
HeaderText
=
"Course Name"
ColumnEditorID
=
"CourseNameEditor"
HeaderStyle-Width
=
"380px"
Resizable
=
"false"
></
telerik:GridBoundColumn
>
<
telerik:GridDateTimeColumn
UniqueName
=
"FromDate"
DataField
=
"FromDate"
HeaderText
=
"From"
DataFormatString
=
"{0:dd/MM/yyyy}"
HeaderStyle-Width
=
"80px"
Resizable
=
"false"
ItemStyle-HorizontalAlign
=
"Center"
></
telerik:GridDateTimeColumn
>
<
telerik:GridDateTimeColumn
UniqueName
=
"ToDate"
DataField
=
"ToDate"
HeaderText
=
"To"
DataFormatString
=
"{0:dd/MM/yyyy}"
HeaderStyle-Width
=
"80px"
Resizable
=
"false"
ItemStyle-HorizontalAlign
=
"Center"
></
telerik:GridDateTimeColumn
>
<
telerik:GridBoundColumn
UniqueName
=
"Venue"
DataField
=
"Venue"
HeaderText
=
"Venue"
ColumnEditorID
=
"VenueEditor"
HeaderStyle-Width
=
"80px"
Resizable
=
"false"
ItemStyle-HorizontalAlign
=
"Center"
></
telerik:GridBoundColumn
>
<
telerik:GridDropDownColumn
UniqueName
=
"Category"
HeaderText
=
"Category"
DataField
=
"CatID"
HeaderStyle-Width
=
"160px"
Resizable
=
"false"
ItemStyle-HorizontalAlign
=
"Center"
></
telerik:GridDropDownColumn
>
</
Columns
>
<
NoRecordsTemplate
>
<
div
id
=
"NoRecordWrapper"
>No Courses available!</
div
>
</
NoRecordsTemplate
>
</
MasterTableView
>
<
HeaderStyle
Font-Bold
=
"true"
HorizontalAlign
=
"Center"
/>
<
ClientSettings
EnableAlternatingItems
=
"true"
>
</
ClientSettings
>
</
telerik:RadGrid
>
ItemDataBound (VB):
Protected
Sub
CoursesDataBound(
ByVal
sender
As
Object
,
ByVal
e
As
GridItemEventArgs)
Handles
CoursesGrid.ItemDataBound
Try
'--------------------------------------------------------
' 1. Display (Regular) Mode
'--------------------------------------------------------
If
TypeOf
e.Item
Is
GridDataItem
Then
' 1.1 Get reference of current Item & its Data
'----------------------------------------------------
Dim
courseRec
As
GridDataItem =
CType
(e.Item, GridDataItem)
Dim
courseInfo
As
DataRowView =
CType
(courseRec.DataItem, DataRowView)
' 1.2 Set style of Arabic content
'----------------------------------------------------
If
Not
IsDBNull(courseInfo(
"Locale"
))
Then
courseRec(
"CourseName"
).CssClass =
"arabicText"
courseRec(
"CourseName"
).HorizontalAlign = HorizontalAlign.Right
If
Not
IsDBNull(courseInfo(
"Venue"
))
Then
courseRec(
"Venue"
).CssClass =
"arabicText"
End
If
End
If
' 1.3 Replace Subject ID with its Description
'----------------------------------------------------
Dim
catID
As
String
= courseInfo(
"CatID"
)
Dim
catDesc
As
String
= CodeLibrary.CatList.Item(catID)
courseRec(
"Category"
).Text = catDesc
End
If
'--------------------------------------------------------
' 2. Edit/Insert Mode
'--------------------------------------------------------
If
TypeOf
e.Item
Is
GridEditableItem
AndAlso
CType
(e.Item, GridEditableItem).IsInEditMode
Then
' 2.1 Get reference of Edit Manager
'----------------------------------------------------
Dim
editedItem
As
GridEditableItem =
CType
(e.Item, GridEditableItem)
Dim
editMan
As
GridEditManager = editedItem.EditManager
' 2.2 Handle 'Category' DropDownList
'----------------------------------------------------
' 2.2.1 Get reference of respective ColumnEditor
' ................................................
Dim
subjectEditor
As
GridDropDownListColumnEditor =
CType
(editMan.GetColumnEditor(
"Category"
), GridDropDownListColumnEditor)
Dim
subjectsList
As
RadComboBox = subjectEditor.ComboBoxControl
' 2.2.2 Populate
' ................................................
subjectEditor.DataSource = CodeLibrary.CatList
subjectEditor.DataTextField =
"Value"
subjectEditor.DataValueField =
"Key"
subjectEditor.DataBind()
subjectsList.Items.Insert(0,
New
RadComboBoxItem(
"--- SELECT ---"
,
"XX"
))
' 2.2.3 Set Selected Value
' ................................................
subjectsList.SelectedValue =
"XX"
If
Not
e.Item.OwnerTableView.IsItemInserted
Then
subjectsList.SelectedValue = e.Item.DataItem(
"CatID"
)
End
If
' 2.2.4 Set Width
' ................................................
subjectsList.Width = Unit.Pixel(200)
' 2.3 Style 'Course Name' if Arabic
'----------------------------------------------------
Dim
nameEditor
As
GridTextBoxColumnEditor =
CType
(editMan.GetColumnEditor(
"CourseName"
), GridTextBoxColumnEditor)
Dim
textColumn
As
TextBox = nameEditor.TextBoxControl
If
Not
IsDBNull(e.Item.DataItem(
"Locale"
))
Then
textColumn.CssClass =
"arabicText alignRight"
End
If
' 2.4 Disable 'CourseID' on Edit
'----------------------------------------------------
If
Not
TypeOf
e.Item
Is
IGridInsertItem
Then
Dim
idEditor
As
GridTextBoxColumnEditor =
CType
(editMan.GetColumnEditor(
"CourseID"
), GridTextBoxColumnEditor)
idEditor.TextBoxControl.Enabled =
False
End
If
End
If
Catch
ex
As
Exception
Dim
errorMsg
As
String
=
String
.Format(
"â–º CoursesDataBound: [{0}]"
, ex.Message)
DisplayFeedback(
"page"
,
Nothing
, errorMsg)
End
Try
End
Sub
I thought of handling each process separately, but I will end up with redundant code!
Many thanks in advance.