Hi,
I have a series of user control that inherit from RadComboBox. They are used throughout the app, so this is primarily for the purpose of consistency and code re-use. However, I cannot seem to get my default 'Select a <xyz>' item to be the selected item upon the first page load. They show up in the drop-down but the text area of the combo box is blank until Postback, at which time it shows the 'Select a <xyz>' item correctly (assuming the user didn't pick anything).
Everything else seems to be working fine. Frankly, though, my OOP chops are a bit rusty and so I am wondering if I am doing this completely wrong.
Little help?
I have a series of user control that inherit from RadComboBox. They are used throughout the app, so this is primarily for the purpose of consistency and code re-use. However, I cannot seem to get my default 'Select a <xyz>' item to be the selected item upon the first page load. They show up in the drop-down but the text area of the combo box is blank until Postback, at which time it shows the 'Select a <xyz>' item correctly (assuming the user didn't pick anything).
Everything else seems to be working fine. Frankly, though, my OOP chops are a bit rusty and so I am wondering if I am doing this completely wrong.
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
OSIRISModel;
namespace
Telerik.Web.UI.OSIRIS
{
/// <summary>Summary description for OS_JobStatusComboBox</summary>
public
class
OS_JobStatusComboBox : RadComboBox
{
#region Constructor
public
OS_JobStatusComboBox()
{
//
// TODO: Add constructor logic here
//
}
#endregion
#region Control Events
protected
override
void
OnLoad(EventArgs e)
{
if
(!Page.IsPostBack)
{
OSIRISEntities context = ((OSIRISPage)Page).OSIRISContext;
List<JobStatu> items = context.JobStatus.ToList<JobStatu>();
this
.DataTextField =
"Description"
;
this
.DataValueField =
"ID"
;
this
.DataSource = items;
this
.RegisterWithScriptManager =
false
;
this
.AppendDataBoundItems =
true
;
this
.Items.Insert(0,
new
RadComboBoxItem(
"Select a Job Status"
,
""
));
this
.SelectedIndex = 0;
}
}
// This is to prevent double-binding in cases where this control is used inside another control that causes Child Databinding (such as Formview)
private
bool
Bound =
false
;
protected
override
void
OnDataBound(EventArgs e) { Bound =
true
; }
protected
override
void
OnPreRender(EventArgs e) {
if
(Bound ==
false
) {
this
.DataBind(); } }
#endregion
}
}
Little help?