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

Listbox DataTextField with more than one field

3 Answers 224 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Bob
Top achievements
Rank 1
Bob asked on 02 May 2014, 06:00 PM
I would like the Text to contain the combination of the data source's id and name fields.  For example the control:

<telerik:RadListBox runat="server" ID="lstAvailableRemarkCode" Width="500px"<br>                                       Height="300px" SelectionMode="Multiple" AutoPostBackOnReorder="true" EnableDragAndDrop="true"<br>                 OnDropped="RadListBox_Dropped" AllowTransfer="true" TransferToID="lstAssignedRemarkCode"<br>                     ButtonSettings-RenderButtonText="true" Localization-ToRight="Add" Localization-ToLeft="Remove"<br>               ButtonSettings-ShowTransferAll="False" ButtonSettings-ShowReorder="False" ButtonSettings-ShowDelete="False"
    ButtonSettings-HorizontalAlign="Center" ButtonSettings-VerticalAlign="Middle"
    ButtonSettings-AreaWidth="30px"
    DataTextField="RemarkCodeID,Name" DataTextFormatString="{0} - {1}" DataValueField="RemarkCodeID"    
    OnItemDataBound="lstAvailableRemarkCode_ItemDataBound">
    <ButtonSettings AreaWidth="100" />
</telerik:RadListBox>

But in code behind I get an error that source does not have a field 'RemarkCodeID,Name' at the DataBind:

Is there a way I can Implement this?

3 Answers, 1 is accepted

Sort by
0
Bob
Top achievements
Rank 1
answered on 02 May 2014, 06:32 PM
OK, I am able to do this with Templates and combining the fields but now the remove puts a blank row in the original ListBox.
0
Bob
Top achievements
Rank 1
answered on 02 May 2014, 07:52 PM
Here is the updated html:
<td colspan="2">
    <telerik:RadListBox runat="server" ID="lstAvailableRemarkCode" Width="600px"
    Height="300px" SelectionMode="Multiple" AutoPostBackOnReorder="true" EnableDragAndDrop="true"
    OnDropped="RadListBox_Dropped" AllowTransfer="true" TransferToID="lstAssignedRemarkCode"
    ButtonSettings-RenderButtonText="true" Localization-ToRight="Add" Localization-ToLeft="Remove"
    ButtonSettings-ShowTransferAll="False" ButtonSettings-ShowReorder="False" ButtonSettings-ShowDelete="False"
    ButtonSettings-HorizontalAlign="Center" ButtonSettings-VerticalAlign="Middle"
    ButtonSettings-AreaWidth="100px" DataValueField="RemarkCodeID"
    OnItemDataBound="lstAvailableRemarkCode_ItemDataBound">
     <ButtonSettings AreaWidth="100" />
         <ItemTemplate>
            <asp:Label ID="lblAvailableRemarkCode" runat="server" Text='<%# String.Format("{0} - {1}", Eval("RemarkCodeID"), Eval("Name")) %>' ></asp:Label>
         </ItemTemplate>
    </telerik:RadListBox>
</td>
<td>
    <telerik:RadListBox runat="server" ID="lstAssignedRemarkCode" Width="500px"
        Height="300px" SelectionMode="Multiple" AutoPostBackOnReorder="true" EnableDragAndDrop="true"
        OnDropped="RadListBox_Dropped">
    </telerik:RadListBox>
</td>
0
Nencho
Telerik team
answered on 07 May 2014, 10:33 AM
Hello Bob,

Using the ItemTemplate of the RadListBox is the correct approach for achieving the desired rendering. However, I am afraid that I am not quite sure that I had fully understood the currently faced issue. Could you elaborate a bit more on the matter?

Regards,
Nencho
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
ListBox
Asked by
Bob
Top achievements
Rank 1
Answers by
Bob
Top achievements
Rank 1
Nencho
Telerik team
Share this question
or