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

'<%# Bind("MyProperty")>' in code-server

2 Answers 56 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Nguyen
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: 

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

2 Answers, 1 is accepted

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

I still need your help.

Please help me!

Tags
Grid
Asked by
Nguyen
Top achievements
Rank 1
Answers by
Nguyen
Top achievements
Rank 1
Share this question
or