Hi telerik team.
My purpose is create a column that have a combo as a editor, and when user choose the item in combo box, it send both ID and Code back to the server to bind to datacontext of the row.
To do dat, I have a Template column in Markup code:
<
telerik:GridTemplateColumn
>
<
ItemTemplate
>
<
asp:Label
Text
=
'<%# Bind('
Code')%> runat="server" ID=Label1></
asp:Label
>
</
ItemTemplate
>
<
EditItemTemplate
>
<
telerik:RadComboBox
runat
=
"server"
ID
=
"col_Editor"
SelectedValue='<%# Bind("ID")%>'
Text='<%# Bind("Code")%>'
DataTextField="Code"
DataValueField="ID"></
telerik:RadComboBox
>
</
EditItemTemplate
>
</
telerik:GridTemplateColumn
>
It work fine. But now, i want to wrap this into 1 class call "MyComboboxColumn" and the problem is i can not find the way to make a '<%# Bind("")>' tag in the behind code.
My class look like:
Public
Class
MyComboboxColumn
Inherits
GridTemplateColumn
Public
Property
DataTextField
As
String
Public
Property
DataValueField
As
String
Public
Overrides
Sub
PrepareCell(cell
As
TableCell, item
As
GridItem)
If
TypeOf
item
Is
GridDataItem
AndAlso
TypeOf
item
Is
MyEntity
Then
Dim
ent =
CType
(item.DataItem, MyEntity)
Dim
displayText = ent.GetValueByPropertyName(DataTextField)
If
Not
item.IsInEditMode
Then
cell.Text = displayText
Else
Dim
combo
As
RadComboBox = cell.FindControl(
Me
.UniqueName &
"_Editor"
)
combo.Text = displayText
combo.SelectedValue = ent.GetValueByPropertName(DataValueField)
End
If
MyBase
.PrepareCell(cell, item)
End
If
End
Sub
Protected
Overrides
Function
CreateDefaultColumnEditor()
As
IGridColumnEditor
Return
New
MyComboboxColumn_Editor(
Me
)
End
Function
End
Class
Public
Class
MyComboboxColumn_Editor
Inherits
GridTemplateColumnEditor
Public
Property
Owner
As
MyComboboxColumn
Public
Sub
New
(_owner
As
MyComboboxColumn)
Owner = _owner
End
Sub
Protected
Overrides
Sub
AddControlsToContainer()
Dim
combo
As
New
RadComboBox
With
combo
.ID = Owner.UniqueName &
"_Editor"
.DataSource = MyDataSource()
.DataValueField = Owner.DataValueField
.DataTextField = Owner.DataTextField
.DataBind()
End
With
HtmlContainerControl.Controls.Add(combo)
End
Sub
End
Class
I can send the value and text to the editor. But i do not know how to send back from editor to the container.
Please help me,
Thank you.