aspnet-devexpress-dot-web-dot-aspxdatawebcontrolbase-d5a0e29a.md
Occurs after the server control is bound to a data source.
Namespace : DevExpress.Web
Assembly : DevExpress.Web.v25.2.dll
NuGet Package : DevExpress.Web
public event EventHandler DataBound
Public Event DataBound As EventHandler
The DataBound event's data class is EventArgs.
This event notifies the server control that data binding was completed.
The following code snippet handles DataBound events to add none elements to ComboBox editors after they are bound to data:
Run Demo: Data Editors - Enable on Client
<script type="text/javascript">
function OnTechnologyChanged(control) {
cbProduct.SetSelectedIndex(0);
cbVersion.SetSelectedIndex(0);
CheckControlsEnabled();
if (control.GetValue() != "")
cbProduct.PerformCallback(control.GetText());
}
function OnProductComboBoxEndCallback(control) {
control.SetFocus();
}
function OnProductChanged(control) {
cbVersion.SetSelectedIndex(0);
CheckControlsEnabled();
if (control.GetValue() != "")
window.setTimeout(function () {
cbVersion.SetFocus();
}, 100);
}
function CheckControlsEnabled() {
cbProduct.SetEnabled(cbTechnology.GetSelectedIndex() > 0);
cbVersion.SetEnabled(cbProduct.GetSelectedIndex() > 0);
}
</script>
<dx:ASPxLabel ID="lblTechnology" runat="server" Text="Technology:" AssociatedControlID="cbTechnology" />
<dx:ASPxComboBox ID="cbTechnology" ClientInstanceName="cbTechnology" runat="server" Width="200px"
TextField="Name" SelectedIndex="0" DataSourceID="xmlTechnology"
OnDataBound="cbTechnology_DataBound">
<ClientSideEvents SelectedIndexChanged="OnTechnologyChanged" />
</dx:ASPxComboBox>
<dx:ASPxLabel ID="lblProduct" runat="server" Text="Product:" AssociatedControlID="cbProduct" />
<dx:ASPxComboBox ID="cbProduct" ClientInstanceName="cbProduct" runat="server" Width="200px"
TextField="Name" SelectedIndex="0" DataSourceID="xmlProduct" OnCallback="cbProduct_Callback"
OnDataBound="cbProduct_DataBound" >
<ClientSideEvents SelectedIndexChanged="OnProductChanged" EndCallback="OnProductComboBoxEndCallback" />
</dx:ASPxComboBox>
<dx:ASPxLabel ID="lblVersion" runat="server" Text="Version:" AssociatedControlID="cbVersion" />
<dx:ASPxComboBox ID="cbVersion" ClientInstanceName="cbVersion" runat="server" Width="200px" SelectedIndex="0">
<Items>
<dx:ListEditItem Text="(none)" Value="none" />
<dx:ListEditItem Text="v2016 vol2.0" Value="v16.2" />
<dx:ListEditItem Text="v2017 vol1.0" Value="v17.1" />
<dx:ListEditItem Text="v2017 vol2.0" Value="v17.2" />
</Items>
</dx:ASPxComboBox>
protected void Page_Load(object sender, EventArgs e) {
if(!IsCallback) {
cbProduct.SelectedIndex = 0;
cbProduct.ClientEnabled = false;
cbVersion.SelectedIndex = 0;
cbVersion.ClientEnabled = false;
}
}
protected void SetNullItem(object control) {
ASPxComboBox cb = (ASPxComboBox)control;
if(cb != null) {
ListEditItem item = new ListEditItem("(none)", "");
cb.Items.Insert(0, item);
cb.SelectedItem = item;
}
}
protected void cbTechnology_DataBound(object sender, EventArgs e) {
SetNullItem(sender);
}
protected void cbProduct_DataBound(object sender, EventArgs e) {
SetNullItem(sender);
}
protected void cbProduct_Callback(object source, CallbackEventArgsBase e) {
xmlProduct.XPath = string.Format("//Technology[@Name='{0}']/Product", e.Parameter);
DataBind();
}
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If Not IsCallback Then
cbProduct.SelectedIndex = 0
cbProduct.ClientEnabled = False
cbVersion.SelectedIndex = 0
cbVersion.ClientEnabled = False
End If
End Sub
Protected Sub SetNullItem(ByVal control As Object)
Dim cb As ASPxComboBox = DirectCast(control, ASPxComboBox)
If cb IsNot Nothing Then
Dim item As New ListEditItem("(none)", "")
cb.Items.Insert(0, item)
cb.SelectedItem = item
End If
End Sub
Protected Sub cbTechnology_DataBound(ByVal sender As Object, ByVal e As EventArgs)
SetNullItem(sender)
End Sub
Protected Sub cbProduct_DataBound(ByVal sender As Object, ByVal e As EventArgs)
SetNullItem(sender)
End Sub
Protected Sub cbProduct_Callback(ByVal source As Object, ByVal e As CallbackEventArgsBase)
xmlProduct.XPath = String.Format("//Technology[@Name='{0}']/Product", e.Parameter)
DataBind()
End Sub
See Also