Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
345
Preventing WebCombo from throwing an exception on render when the datasource is null or does not contain the DataTextField or DataValueField column.
posted

I have a WebCombo that will always have a DataTextField and DataValueField specified, but sometimes, its DataSource will be null or will not contain matching columns.  In this case, I would like the combo to be visible but unusable.

What do you guys think the most elegant solution is?

  • 29417
    Suggested Answer
    Offline posted

    Hello randrews, 

    I know it’s been a while since you’ve posted this but if you still need assistance with it I’d be glad to help.

     

    One possible solution for this issue is the following:

     

    Depending on the content of your DataSource you could disable the WebCombo on WebCombo1_Init event. For example:

     

    protected void WebCombo1_Init(object sender, EventArgs e)

        {

     

            table = MakeTable(); //get content of data

            if (table==null ) //check if it's nulll

            {

                WebCombo combo = (WebCombo)sender;

                combo.Enabled = false; //disable combo

            }

            else

            {

                WebCombo1.DataValueField = "id";

                WebCombo1.DataTextField = "Item";

     

                WebCombo1.DataSource = table;

                WebCombo1.DataBind();

            }

        }

     

     

    This will disable the WebCombo if the data is null and databind it if it isn’t.

     

    If you need further assistance with this don’t hesitate to ask.

     

    Best Regards,

    Maya Kirova

    Developer Support Engineer

    Infragistics, Inc.

    http://ko.infragistics.com/support