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.
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">
<
html
xmlns
=
"http://www.w3.org/1999/xhtml"
>
<
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
>