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

RadComboBox datasource empty on postback

1 Answer 228 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Craig
Top achievements
Rank 1
Craig asked on 21 May 2012, 07:28 PM
Hello,

I am assigning a radcombobox's datasource property a List(of Person) and then databinding it.  I have the Autopost property set to true so when a selection is made it will post back.  Unfortunately, the radcombobox's datasource property is nothing when the postback occurs.  Is there something I need to do to keep the datasource from being left to nothing?  Since I can't attach a zip file I am providing code snippets.
Imports Telerik.Web.UI
Imports System.Linq
 
Partial Class _Default
    Inherits System.Web.UI.Page
 
    Private Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
 
        If Not Page.IsPostBack Then
            Dim people = {New Person With {.Name = "Craig", .UserId = "Wil1"}, New Person With {.Name = "Kaitlyn", .UserId = "Wil2"}, New Person With {.Name = "Ben", .UserId = "Wil3"}}.ToList
 
            radCbo.DataTextField = "Name" : radCbo.DataValueField = "UserId"
            radCbo.DataSource = people
            radCbo.DataBind()
        End If
 
    End Sub
 
    Private Sub radCbo_SelectedIndexChanged(sender As Object, e As Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs) Handles radCbo.SelectedIndexChanged
        Dim ds = radCbo.DataSource
        Dim i = radCbo.SelectedItem.DataItem
    End Sub
End Class
 
 
Public Class Person
    Public Property Name As String
    Public Property UserId As String
End Class

<%@ Page Language="VB" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="RadControlsWebAppComboTest._Default" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<head runat="server">
    <title></title>
    <telerik:RadStyleSheetManager id="RadStyleSheetManager1" runat="server" />
</head>
<body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        <Scripts>
            <%--Needed for JavaScript IntelliSense in VS2010--%>
            <%--For VS2008 replace RadScriptManager with ScriptManager--%>
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
        </Scripts>
    </telerik:RadScriptManager>
    <script type="text/javascript">
        //Put your JavaScript code here.
    </script>
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
    </telerik:RadAjaxManager>
    <div>
    <telerik:RadComboBox runat="server" ID="radCbo" AutoPostBack="true" EnableViewState="true"></telerik:RadComboBox>
    </div>
    </form>
</body>
</html>

1 Answer, 1 is accepted

Sort by
0
Ivana
Telerik team
answered on 22 May 2012, 02:56 PM
Hello Craig,

Take a look at the following forum threads discussing the issues you experience:

Regards,
Ivana
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
ComboBox
Asked by
Craig
Top achievements
Rank 1
Answers by
Ivana
Telerik team
Share this question
or