HBM.HBMMaster.BindDropdown C# (CSharp) Method

BindDropdown() public method

This method binds a drop down list or a checkbox list to a given DataSet
public BindDropdown ( string textField, string valueField, DataSet dsDataSet, System webControl, int tableNo ) : void
textField string /// Field from the datasource to use for the option text ///
valueField string /// Field from the datasource to use for the option value ///
dsDataSet System.Data.DataSet /// DataSource ///
webControl System /// Name of the Control ///
tableNo int
return void
        public void BindDropdown(string textField, string valueField, DataSet dsDataSet, System.Web.UI.WebControls.WebControl webControl, int tableNo = 0)
        {
            if (webControl is DropDownList)
            {
                DropDownList dropDown = (DropDownList)webControl;
                dropDown.DataSource = dsDataSet.Tables[tableNo];

                //set DataTextField property only if it is not null
                if (null != textField)
                {
                    dropDown.DataTextField = textField;
                }

                //set DataValueField property only if it is not null
                if (null != valueField)
                {
                    dropDown.DataValueField = valueField;
                }
                dropDown.DataBind();

            }
            else if (webControl is CheckBoxList)
            {
                CheckBoxList checkBoxList = (CheckBoxList)webControl;
                checkBoxList.DataSource = dsDataSet.Tables[tableNo];

                //set DataTextField property only if it is not null
                if (null != textField)
                {
                    checkBoxList.DataTextField = textField;
                }

                //set DataValueField property only if it is not null
                if (null != valueField)
                {
                    checkBoxList.DataValueField = valueField;
                }
                checkBoxList.DataBind();
            }
        }