I know that I'm missing something, but could someone give me simple example code for this?
So far I have this:
There are two textboxes, a button, and two listboxes on the page, currently I'm only concerned with RadListBox1. I want to be able to add the values from the textboxes to labels (or text) in a template format in the listbox when the user clicks the button. I want to be able to set the position and color of the text. The value portion of the item will be an ID that doesn't need to be displayed.
Currently this all works if I don't use a template and I just concatenate the text from both textboxes. But I don't know how to do this with a template. I've put labels in the itemtemplate section below with text="#= Text #" but nothing displays in the listbox. The item is added and it has the right text and value, but it's just a very narrow row with no text showing.
Relevant code below:
<script type="text/javascript">
var listBox;
function pageLoad() {
listBox = $find("<%= RadListBox1.ClientID %>");
}
function addItem() {
var itemText = $find("<%= RadTextBox1.ClientID %>").get_value();
//Set a value also to mimic having an ID column in the control.
var itemValue = 15
if (!itemText) {
alert("Please specify the text for the new item.");
return false;
}
var itemText2 = $find("<%= RadTextBox2.ClientID %>").get_value();
if (!itemText2) {
alert("Please specify text2 for the new item.");
return false;
}
var itemFullText = "" + itemText + " ; Volume: " + itemText2
listBox.trackChanges();
//Instantiate a new client item
var item = new Telerik.Web.UI.RadListBoxItem();
item.set_text(itemFullText);
item.set_value(itemValue);
item.set_selected(true);
item.bindTemplate();
listBox.get_items().add(item);
item.scrollIntoView();
listBox.commitChanges();
return false;
}
</script>
<telerik:RadTextBox ID="RadTextBox1" Runat="server">
</telerik:RadTextBox>
<telerik:RadTextBox ID="RadTextBox2" Runat="server">
</telerik:RadTextBox>
<telerik:RadButton ID="RadButton1" runat="server" AutoPostBack="False"
onclientclicked="addItem" Text="RadButton">
</telerik:RadButton>
<br />
<br />
<telerik:RadListBox ID="RadListBox1" runat="server" AllowDelete="True"
AllowReorder="True" AllowTransfer="True" TransferToID="RadListBox2" Height="150px" Width="300px">
<ItemTemplate>
</ItemTemplate>
<ButtonSettings TransferButtons="All"></ButtonSettings>
</telerik:RadListBox>
<telerik:RadListBox ID="RadListBox2" runat="server" Height="150px" Width="300px">
<ButtonSettings TransferButtons="All">
</ButtonSettings>
</telerik:RadListBox>
So far I have this:
There are two textboxes, a button, and two listboxes on the page, currently I'm only concerned with RadListBox1. I want to be able to add the values from the textboxes to labels (or text) in a template format in the listbox when the user clicks the button. I want to be able to set the position and color of the text. The value portion of the item will be an ID that doesn't need to be displayed.
Currently this all works if I don't use a template and I just concatenate the text from both textboxes. But I don't know how to do this with a template. I've put labels in the itemtemplate section below with text="#= Text #" but nothing displays in the listbox. The item is added and it has the right text and value, but it's just a very narrow row with no text showing.
Relevant code below:
<script type="text/javascript">
var listBox;
function pageLoad() {
listBox = $find("<%= RadListBox1.ClientID %>");
}
function addItem() {
var itemText = $find("<%= RadTextBox1.ClientID %>").get_value();
//Set a value also to mimic having an ID column in the control.
var itemValue = 15
if (!itemText) {
alert("Please specify the text for the new item.");
return false;
}
var itemText2 = $find("<%= RadTextBox2.ClientID %>").get_value();
if (!itemText2) {
alert("Please specify text2 for the new item.");
return false;
}
var itemFullText = "" + itemText + " ; Volume: " + itemText2
listBox.trackChanges();
//Instantiate a new client item
var item = new Telerik.Web.UI.RadListBoxItem();
item.set_text(itemFullText);
item.set_value(itemValue);
item.set_selected(true);
item.bindTemplate();
listBox.get_items().add(item);
item.scrollIntoView();
listBox.commitChanges();
return false;
}
</script>
<telerik:RadTextBox ID="RadTextBox1" Runat="server">
</telerik:RadTextBox>
<telerik:RadTextBox ID="RadTextBox2" Runat="server">
</telerik:RadTextBox>
<telerik:RadButton ID="RadButton1" runat="server" AutoPostBack="False"
onclientclicked="addItem" Text="RadButton">
</telerik:RadButton>
<br />
<br />
<telerik:RadListBox ID="RadListBox1" runat="server" AllowDelete="True"
AllowReorder="True" AllowTransfer="True" TransferToID="RadListBox2" Height="150px" Width="300px">
<ItemTemplate>
</ItemTemplate>
<ButtonSettings TransferButtons="All"></ButtonSettings>
</telerik:RadListBox>
<telerik:RadListBox ID="RadListBox2" runat="server" Height="150px" Width="300px">
<ButtonSettings TransferButtons="All">
</ButtonSettings>
</telerik:RadListBox>