RadListBox Inside EditForm

2 posts, 0 answers
  1. Manuel
    Manuel avatar
    1 posts
    Member since:
    Oct 2012

    Posted 17 Dec 2014 Link to this post

    Hi All

    This is my scenario

    I have a RadGrid, then I have an EditFormTemplate and inside I have a RadListBox, I'm able to select a value from codebehind, but I want to scroll the ListBox to the selected when the EditForm is showing, I followed this post  but I'm not able to do it.

    Here is my test code 

    ASP
    <telerik:RadGrid ID="Radgrid1" runat="server" DataSourceID="SqlDataSource1" AutoGenerateColumns="false"
        AutoGenerateEditColumn="true">
        <MasterTableView>
            <EditFormSettings EditFormType="Template">
            <PopUpSettings Width="620px" Modal="false" Height="550px" />
                <FormTemplate>
                    <telerik:RadListBox ID="RadListBox1" runat="server" DataSource="DS" OnClientSelectedIndexChanged="selectedIndexChanged">
                    </telerik:RadListBox>
                </FormTemplate>
            </EditFormSettings>
            <Columns>
                <telerik:GridBoundColumn DataField="OrderID" HeaderText="OrderID">
                </telerik:GridBoundColumn>
            </Columns>
        </MasterTableView>
    </telerik:RadGrid>

    Code Behind
    Protected Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemDataBound
     
            If TypeOf e.Item Is GridDataItem Then
                Dim editItem As GridDataItem = DirectCast(e.Item, GridDataItem)      
                Dim ddlCurrency As RadListBox = DirectCast(editItem.FindControl("RadListBox1"), RadListBox)
     
                If ddlCurrency IsNot Nothing Then
                    Dim item As RadListBoxItem = ddlCurrency.FindItemByText(strCurrency)
                    If item IsNot Nothing Then
                        ddlCurrency.SelectedValue = hdnValue.Value
                    End If
                End If
             End If
         End Sub

    Javascript
    function selectedIndexChanged(sender, args)
    {
        var item = args.get_item();
        item.scrollIntoView();
    }

    I know that I can only use the scrollIntoView() inside JavaScript but the function  selectedIndexChanged is not firing, is there a way to scroll when I select the item in the code behind or server-side? 
    Thanks in advance
  2. Peter Filipov
    Admin
    Peter Filipov avatar
    1028 posts

    Posted 22 Dec 2014 Link to this post

    Hello Manuel,

    Here is my suggestion for your case:
    1. Handle the pageLoad event at the client side
    2. Find the RadListBox control
    3. Get the selected item by calling get_selectedItem() method, after that invoke the scroll into view function.

    Regards,
    Peter Filipov
    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.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top