item template set value of control on item databound

2 posts, 0 answers
  1. Jon
    Jon avatar
    30 posts
    Member since:
    Apr 2009

    Posted 15 Apr Link to this post

    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?

     

     

     

     

     

     

     

     

     

     

  2. Jon
    Jon avatar
    30 posts
    Member since:
    Apr 2009

    Posted 16 Apr in reply to Jon Link to this post

    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
Back to Top