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();
}
}