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

item template set value of control on item databound

1 Answer 146 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Jon
Top achievements
Rank 2
Veteran
Jon asked on 15 Apr 2020, 04:42 PM

I have a rad list box as follows:

<telerik:RadListBox runat="server" ID="RadListBox1" Height="375px" Width="750px" DataSourceID="SqlDataSource2"
    AllowReorder="true" AutoPostBackOnReorder="true" EnableDragAndDrop="true" ButtonSettings-ShowReorder="true"
    AllowAutomaticUpdates="true" DataKeyField="SectionSort_ID" DataTextField="Header_Title" DataValueField="Header_Image" DataSortField="SectionSort_SortOrder"SelectionMode="Multiple">
    <ItemTemplate>
        <telerik:RadNumericTextBox RenderMode="Lightweight" runat="server" ID="ItemNo" Width="60px" MinValue="1"
            MaxValue="50" ShowSpinButtons="true" Value='1' NumberFormat-DecimalDigits="0" Skin="Bootstrap">
        </telerik:RadNumericTextBox>
        <img class="product-image" src='<%# DataBinder.Eval(Container, "Value")%>'>
        <span class="product-title"><%# DataBinder.Eval(Container, "Text")%></span>
    </ItemTemplate>
</telerik:RadListBox>

 

I want to set the RadNumericTextBox value in the databound event

I have tried the following:

Protected Sub RadListBox1_ItemDataBound(sender As Object, e As RadListBoxItemEventArgs) Handles RadListBox1.ItemDataBound
    If TypeOf e.Item Is RadListBoxItem Then
        Dim item = CType(e.Item, RadListBoxItem)
        Dim ItemNo As RadNumericTextBox = CType(item.FindControl("ItemNo"), RadNumericTextBox)
        ItemNo.Value = e.Item.DataItem("SectionSort_ItemNo")
    End If
End Sub

 

But I get this:

 

Specified cast is not valid.

based on this line

ItemNo.Value = e.Item.DataItem("SectionSort_ItemNo")

So basically how do i set the value of the text box in the databound event?

 

 

 

 

 

 

 

 

 

 

1 Answer, 1 is accepted

Sort by
0
Jon
Top achievements
Rank 2
Veteran
answered on 16 Apr 2020, 10:40 AM

changed the code as follows now works:

 

Literal1.Text += e.Item.GetType.ToString & "<br>"
Dim item = CType(e.Item, RadListBoxItem)
Dim ItemNo As RadNumericTextBox = CType(item.FindControl("ItemNo"), RadNumericTextBox)
ItemNo.Value = e.Item.DataItem("SectionSort_ItemNo").ToString
Tags
ListBox
Asked by
Jon
Top achievements
Rank 2
Veteran
Answers by
Jon
Top achievements
Rank 2
Veteran
Share this question
or