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

Dynamic data for template in listBox

1 Answer 118 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Taraman
Top achievements
Rank 1
Taraman asked on 03 Dec 2010, 09:27 AM
Dear Telerik,

I have created a template inside listBox like your example in the demo: http://demos.telerik.com/aspnet-ajax/listbox/examples/functionality/templates/defaultcs.aspx

but I don't want to create a static data, so I have created a list like the followin:
      public class Spinning
    {
        public string Title { get; set; }
        public double Price { get; set; }
        public int Quantity { get; set; }
    }
  
    void RadListBox5_Load()
    {
        List<Spinning> SpinningList = new List<Spinning> 
        
            new Spinning { Title = "Spinning Reel 1", Price = 99, Quantity = 1 },
            new Spinning { Title = "Spinning Reel 2", Price = 199, Quantity = 1 }
        };
  
        RadListBox5.DataSource = SpinningList;
        RadListBox5.DataBind();
    }
and the the aspx like the following:
<telerik:RadListBox ID="RadListBox5" runat="server" AllowTransfer="true" 
            AutoPostBackOnTransfer="true" Height="200px" OnTransferred="RadListBox5_Transferred" 
            SelectionMode="Multiple" TransferToID="RadListBox6" Width="215px">
            <ButtonSettings ShowTransferAll="false" VerticalAlign="Middle" />
            <ItemTemplate>
              
                <table cellpadding="1" cellspacing="0" border="0">
                    <tr>
                        <td><b><%# DataBinder.Eval(Container, "Attributes['Title']")%></b></td>
                        <td> [Price:</td>
                        <td><%# Convert.ToInt32(DataBinder.Eval(Container, "Attributes['Price']")).ToString("C0") %>]</td>
                    </tr>
                </table>
            </ItemTemplate>
        </telerik:RadListBox>

the data are not displayed !!!!!
can you help me on this?

thanks,
Mohamed Taraman

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 03 Dec 2010, 12:08 PM
Hello Taraman,

 I have modified your code like below .Give a try with it. 

Markup:
<ItemTemplate>
    <%# DataBinder.Eval(Container.DataItem, "Title")%></b></b></td> [Price:
    <%# Convert.ToInt32(DataBinder.Eval(Container.DataItem, "Price")).ToString("C0")%>
</ItemTemplate>

Thanks,
Princy.
Tags
ListBox
Asked by
Taraman
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or