This is a migrated thread and some comments may be shown as answers.
'<%# Bind("MyProperty")>' in code-server
2 Answers 6 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Nguyen asked on 06 Nov 2015, 07:36 AM

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: 

<asp:Label Text='<%# Bind('Code')%> runat="server" ID=Label1></asp:Label>
<telerik:RadComboBox runat="server"
SelectedValue='<%# Bind("ID")%>'
Text='<%# Bind("Code")%>'

 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
                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
        End With
    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.

2 Answers, 1 is accepted

Sort by
Top achievements
Rank 1
answered on 06 Nov 2015, 10:12 AM
Any help please!!!
Top achievements
Rank 1
answered on 10 Nov 2015, 01:18 AM

I still need your help.

Please help me!

Asked by
Top achievements
Rank 1
Answers by
Top achievements
Rank 1
Share this question