public static void BindDropDownList(DataTable dt, DropDownListAjaxHelper ddl, string textField, string valueField, string sort, string filter, string selectedValue, string firstTitle = null) { DataView dv = dt.DefaultView; string srt = dv.Sort; string flt = dv.RowFilter; if (!String.IsNullOrEmpty(sort) && srt != sort) { dv.Sort = sort; } if (!String.IsNullOrEmpty(filter)) { dv.RowFilter = filter; } if (!String.IsNullOrEmpty(firstTitle)) { dv[0][textField] = firstTitle; } ddl.DataSource(dt.DefaultView, valueField, textField); if (selectedValue != null) { ddl.SelectedValue(selectedValue); } dt.RejectChanges(); dv.Sort = srt; dv.RowFilter = flt; }
public static void BindDropDownList(DataTable dt, DropDownListAjaxHelper ddl, string textField, string valueField, string sort = null, string selectedValue = null) { string srt = dt.DefaultView.Sort; if (!String.IsNullOrEmpty(sort) && srt != sort) { dt.DefaultView.Sort = sort; } ddl.DataSource(dt.DefaultView, valueField, textField); if (selectedValue != null) { ddl.SelectedValue(selectedValue); } if (!String.IsNullOrEmpty(sort) && srt != sort) { dt.DefaultView.Sort = srt; } }