How to get the name of failing RadComboBox sourced in declarative programmatic way

0 Answers 80 Views
ComboBox DropDownList
Finwave Spa
Top achievements
Rank 1
Finwave Spa asked on 28 Oct 2022, 01:05 PM
Hi,

I have a project whot lots of aspx pages, each one containing lot's of RadComboBoxes which are populated with declarative Data Sources :for each RadCombBox I define a certaing Object Data Source so to populate each RadComboBox whith proper items

let's consider a page in which I define:

1) the RadComboBox with rcbCDRATEINDEX ID,  which items are coming from odsTBRCFINPRICE_CDRATEINDEX Object Data Source calling the select method GetDataByCDCOMPANY
2) the RadComboBox with rcbCDrcbTPPLAN ID, which items are coming from odsTBRCFINPRICE_TPPLAN Object Data Source calling call the select method GetDataByCDCOMPANY_CUSTTYPE
3) the RadComboBox with rcbPER_SUG ID, which items are coming from odsTBRCFINPRICE_PER_SUG Object Data Source calling call the select method GetDataByCDCOMPANY_PER_SUG


<telerik:RadComboBox ID="rcbCDRATEINDEX" runat="server" DataSourceID="odsTBRCFINPRICE_CDRATEINDEX"
    DataTextField="DSRATEINDEX" DataValueField="CDRATEINDEX" Width="100%" OnClientSelectedIndexChanged="ClientRcbCDRATEINDEX_SelectedIndexChanged" />
<asp:ObjectDataSource ID="odsTBRCFINPRICE_CDRATEINDEX" runat="server"
    OldValuesParameterFormatString="original_{0}" SelectMethod="GetDataByCDCOMPANY"
    TypeName="DataAccessComponent.dsFinancialMarketAndRateTableAdapters.TCRATEINDEXTableAdapter">
    <SelectParameters>
        <asp:ControlParameter ControlID="hCDCOMPANY" DefaultValue="''" Name="CDCOMPANY" PropertyName="Value" Type="String" />
    </SelectParameters>
</asp:ObjectDataSource>
...

...
<telerik:RadComboBox ID="rcbTPPLAN" runat="server" DataSourceID="odsTBRCFINPRICE_TPPLAN"
    DataTextField="DSCUSTOM" DataValueField="CUSTKEY" Width="100%" OnClientSelectedIndexChanged="ClientRcbTPPLAN_OnSelectedIndexChanged" />
<asp:ObjectDataSource ID="odsTBRCFINPRICE_TPPLAN" runat="server"
    OldValuesParameterFormatString="original_{0}" SelectMethod="GetDataByCDCOMPANY_CUSTTYPE"
    TypeName="DataAccessComponent.dsOtherTableAdapters.TBCUSTOMTableAdapter">
    <SelectParameters>
        <asp:ControlParameter ControlID="hCDCOMPANY" DefaultValue="''" Name="CDCOMPANY" PropertyName="Value" Type="String" />
        <asp:Parameter DefaultValue="DEPR_PLAN" Name="CUSTTYPE" Type="String" />
    </SelectParameters>
</asp:ObjectDataSource>
...

...
<telerik:RadComboBox ID="rcbPER_SUG" runat="server" DataSourceID="odsTBRCFINPRICE_PER_SUG"
    DataTextField="DSCUSTOM" DataValueField="CUSTKEY" Width="100%" />
<asp:ObjectDataSource ID="odsTBRCFINPRICE_PER_SUG" runat="server"
    OldValuesParameterFormatString="original_{0}" SelectMethod="GetDataByCDCOMPANY_PER_SUG"
    TypeName="DataAccessComponent.dsOtherTableAdapters.TBCUSTOMTableAdapter">
    <SelectParameters>
        <asp:ControlParameter ControlID="hCDCOMPANY" DefaultValue="''" Name="CDCOMPANY" PropertyName="Value" Type="String" />
        <asp:Parameter DefaultValue="PER_SUG" Name="CUSTTYPE" Type="String" />
    </SelectParameters>
</asp:ObjectDataSource>

Now let's suppose that a developer's bug causes that the method GetDataByCDCOMPANY_CUSTTYPE produces no data.

Then an exception of this kind is generated:

Exception Message: 'System.Web.HttpUnhandledException'.

Exception StackTrace: in System.Web.UI.Page.HandleError(Exception e)
in System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
in System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
in System.Web.UI.Page.ProcessRequest()
in System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)
in System.Web.UI.Page.ProcessRequest(HttpContext context)
in ASP.cpwizardratecard_aspx.ProcessRequest(HttpContext context) in c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\dll\5102107e\48518dac\App_Web_cpwizardratecard.aspx.cdcab7d2.dm-dka8a.0.cs:riga 0
in System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
in System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step)
in System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

[ArgumentOutOfRangeException: Selection out of range
Parameter Name: value]
   Telerik.Web.UI.RadComboBox.PerformDataBinding(IEnumerable dataSource) +287
   Telerik.Web.UI.RadComboBox.OnDataSourceViewSelectCallback(IEnumerable data) +329
   System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +34
   Telerik.Web.UI.RadComboBox.OnDataBinding(EventArgs e) +758
   Telerik.Web.UI.RadComboBox.PerformSelect() +21
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +76
   Telerik.Web.UI.RadComboBox.DataBind() +40
   System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +114
   Telerik.Web.UI.RadComboBox.OnPreRender(EventArgs e) +24
   System.Web.UI.Control.PreRenderRecursiveInternal() +90
   System.Web.UI.Control.PreRenderRecursiveInternal() +163
   System.Web.UI.Control.PreRenderRecursiveInternal() +163
   System.Web.UI.Control.PreRenderRecursiveInternal() +163
   System.Web.UI.Control.PreRenderRecursiveInternal() +163
   System.Web.UI.Control.PreRenderRecursiveInternal() +163
   System.Web.UI.Control.PreRenderRecursiveInternal() +163
   System.Web.UI.Control.PreRenderRecursiveInternal() +163
   System.Web.UI.Control.PreRenderRecursiveInternal() +163
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +906

This kind of exception is a generic one,  because it states that a component Telerik.Web.UI.RadComboBox of the page, fails during it's Data Binding performing.

This exception don't tell me that THE RadComboBox rcbTPPLAN, which use declaratively the method GetDataByCDCOMPANY_CUSTTYPE, fails.

So every time that happens an exception like that above mentioned, we're in the panic, struggling to understand which declaratively sourced Rad Combo Box produce the error.

Is there a way to understand the rad combo box id that produced the exception?
Doncho
Telerik team
commented on 02 Nov 2022, 12:37 PM

Hi Fabio,

The error message "Selection out of range" occurs because something in the backend tries to set a value to the Combo which does not exist.

Please review the backend code (C#), specifically those lines where the value is set to these combos. Instead of setting a selected value, you can try the FindItemByValue() method of the combo instance, set a condition that will check if this item is returned or is null, and mark it as selected.

If you have any questions, please let me know.

Finwave Spa
Top achievements
Rank 1
commented on 02 Nov 2022, 03:49 PM

The trouble is that there is no backend code to review. 

RadComboBoxes (RCBs) in the various aspx pages of my project are sourced from DB only in a declarative manner as I stated in points 1) --> 3).

So if we consider the follow rcbCDRATEINDEX RCB

<telerik:RadComboBox ID="rcbCDRATEINDEX" runat="server" DataSourceID="odsTBRCFINPRICE_CDRATEINDEX"
    DataTextField="DSRATEINDEX" DataValueField="CDRATEINDEX" Width="100%" OnClientSelectedIndexChanged="ClientRcbCDRATEINDEX_SelectedIndexChanged" />
<asp:ObjectDataSource ID="odsTBRCFINPRICE_CDRATEINDEX" runat="server"
    OldValuesParameterFormatString="original_{0}" SelectMethod="GetDataByCDCOMPANY"
    TypeName="DataAccessComponent.dsFinancialMarketAndRateTableAdapters.TCRATEINDEXTableAdapter">
    <SelectParameters>
        <asp:ControlParameter ControlID="hCDCOMPANY" DefaultValue="''" Name="CDCOMPANY" PropertyName="Value" Type="String" />
    </SelectParameters>
</asp:ObjectDataSource>

it's items are populated thanks to Object Data Source odsTBRCFINPRICE_CDRATEINDEX, which used the backend method GetDataByCDCOMPANY() to get item's data from DB.

This is the only way I used in my aspx pages to fill tens of Rad Combo Box: I use a declarative statement on aspx pages, I don't use any imperative code, directly instantiating a RCB corresponding .NET object in aspx.cs class.

It's not possible to follow the way of imperative coding, because I had to maintain tens of RCBs, so it will be too long to realize.

I had also thought about making an asp Custom Control, MyRadComboBox, in which I inherit from RadComboBox class, so to simply substitude the declarative aspx code above with the follow

<telerik:MyRadComboBox
    ID="rcbCDRATEINDEX" runat="server" DataSourceID="odsTBRCFINPRICE_CDRATEINDEX"
    DataTextField="DSRATEINDEX" DataValueField="CDRATEINDEX" Width="100%" OnClientSelectedIndexChanged="ClientRcbCDRATEINDEX_SelectedIndexChanged" />
<asp:ObjectDataSource ID="odsTBRCFINPRICE_CDRATEINDEX" runat="server"
    OldValuesParameterFormatString="original_{0}" SelectMethod="GetDataByCDCOMPANY"
    TypeName="DataAccessComponent.dsFinancialMarketAndRateTableAdapters.TCRATEINDEXTableAdapter">
    <SelectParameters>
        <asp:ControlParameter ControlID="hCDCOMPANY" DefaultValue="''" Name="CDCOMPANY" PropertyName="Value" Type="String" />
    </SelectParameters>
</asp:ObjectDataSource>

In MyRadComboBox I would then device a way to realize a speaking exception with the RCB's ID.

The problem is that I can't reach to build the RCB asp control.

So is it possible to device a solution that give me in the exception the ID of the guilty failed RCB when the filling-declarative-Object-Data-Source-aspx method fail to get a valid set of data from DB? (this last evenience is quite likely to happen within our team developing).

Thank you very much.

No answers yet. Maybe you can help?

Tags
ComboBox DropDownList
Asked by
Finwave Spa
Top achievements
Rank 1
Share this question
or