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

RadListBox Inside EditForm

1 Answer 73 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Manuel
Top achievements
Rank 1
Manuel asked on 17 Dec 2014, 08:18 PM
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

1 Answer, 1 is accepted

Sort by
0
Peter Filipov
Telerik team
answered on 22 Dec 2014, 12:24 PM
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.

 
Tags
ListBox
Asked by
Manuel
Top achievements
Rank 1
Answers by
Peter Filipov
Telerik team
Share this question
or