public static void BindComboBoxData(ComboBox ComboBoxname, DataTable dt, string valueid, string valuedisplay) { DataRow DataRW; DataTable DataTB = new DataTable(); ComboBoxname.DataSource = null; if (dt.Columns.Count > 0) { DataTB = dt; } else { DataTB.Columns.Add(valueid, typeof(string)); DataTB.Columns.Add(valuedisplay, typeof(string)); } DataRW = DataTB.NewRow(); if (DataTB.Rows.Count != 0) { // string planstr = valueid + " " + valuedisplay; ComboBoxname.DataSource = DataTB.DefaultView; ComboBoxname.DataSource = DataTB.AsDataView(); ComboBoxname.ValueMember = valueid; ComboBoxname.DisplayMember = valuedisplay; } else { ComboBoxname.DataSource = null; } }
public static void BindComboBoxDataForSelectAll(ComboBox ComboBoxname, DataTable dt, string valueid, string valuedisplay) { try { DataRow DataRW; DataTable DataTB = new DataTable(); ComboBoxname.DataSource = null; if (dt.Columns.Count > 0) { DataTB = dt; } else { DataTB.Columns.Add(valueid, typeof(string)); DataTB.Columns.Add(valuedisplay, typeof(string)); } DataRW = DataTB.NewRow(); if (DataTB.Rows.Count != 0) { DataRW[valueid] = "0"; DataRW[valuedisplay] = "-- Select All --"; DataTB.Rows.InsertAt(DataRW, 0); // string planstr = valueid + " " + valuedisplay; // ComboBoxname.DataSource = DataTB.DefaultView; ComboBoxname.DataSource = DataTB.AsDataView(); ComboBoxname.ValueMember = valueid; ComboBoxname.DisplayMember = valuedisplay; } else { ComboBoxname.DataSource = null; } } catch { throw; } }