public static void LoadList(DropDownList ddl, string SQL, string ValueField = null, string TextField = null) { try { DataMaven dm = new DataMaven(SQL); DataTable dt = dm.ExecToDataTable(); // Add empty row DataRow dr = dt.NewRow(); dt.Rows.InsertAt(dr, 0); //set the value and Text fields if (ValueField == null) { string s = ddl.ID.Replace("ID", ""); s = s.Replace("Code", ""); ValueField = s + "ID"; TextField = s + "Name"; } ddl.DataValueField = ValueField; ddl.DataTextField = TextField; // Bind data to DropDownList ddl.DataSource = dt; ddl.DataBind(); } catch (Exception ex) { // Display error message Util.jsErrorAlert(ex.Message); } }
public static void LoadList(CheckBoxList chk, string sp = null, string TextField = null, string ValueField = null, string Parms = null, string SelectedColumn = null) { try { if (sp == null) { sp = chk.ID.Replace("ID", ""); sp = sp.Replace("Code", ""); sp = "usp_" + sp + "DDL_Sel"; } DataMaven dm = new DataMaven(sp, Parms); //set the value and Text fields if (ValueField == null) { string s = chk.ID.Replace("ID", ""); s = s.Replace("Code", ""); ValueField = s + "ID"; TextField = s + "Name"; } chk.DataValueField = ValueField; chk.DataTextField = TextField; DataTable dt = dm.ExecToDataTable(); // Bind data to CheckBoxList chk.DataSource = dt; chk.DataTextField = TextField; chk.DataValueField = ValueField; chk.DataBind(); // Set selected items, only if the DataTable contains a "Selected" column if (dt.Columns.Contains("Selected")) { for (int i = 0; i <= chk.Items.Count - 1; i++) { DataRow[] result = dt.Select(SelectedColumn + " = " + chk.Items[i].Value); chk.Items[i].Selected = Convert.ToBoolean(result[0]["Selected"]); } } } catch (Exception ex) { // Display error message Util.jsErrorAlert(ex.Message); } }
public static void LoadList(RadioButtonList rdo, string sp, string TextField, string ValueField, string[,] Parms = null) { try { DataMaven dm = new DataMaven(); System.Data.SqlDbType dType = default(System.Data.SqlDbType); DataTable dt = null; int i = 0; dm.SetSP(sp); if ((Parms != null)) { for (i = 0; i <= Parms.GetUpperBound(1); i++) { if ((Parms != null)) { dType = (SqlDbType)Parms.GetValue(i, 0); dm.AddParameter(Parms.GetValue(i, 1).ToString(), dType, ParameterDirection.Input, Parms.GetValue(i, 2)); } } } dt = dm.ExecToDataTable(); // Bind data to RadioButtonList rdo.DataSource = dt; rdo.DataTextField = TextField; rdo.DataValueField = ValueField; rdo.DataBind(); } catch (Exception ex) { // Display error message Util.jsErrorAlert(ex.Message); } }