Dynamic Fill DDL for asp.net example

public static bool FillDDL(DropDownList ddl, string query, string srtValue, string strText, string strHeader, MySqlDb   mysql, out string error)       
      DataTable tbl = mysql.ExecuteSelect(query);                
      ddl.DataSource = tbl;                
      ddl.DataTextField = strText;                
      ddl.DataValueField = srtValue;                
      ListItem li = new ListItem();
      if (string.Empty.Equals(strHeader))
          li.Text = "Choose";
          li.Text = strHeader;                
      li.Value = "";
      ddl.Items.Insert(0, li);                
      error = "";
      return true;
   catch (Exception ex)            
   { error = ex.Message; return false; }        
}//end fill ddl
the MySqlDb is an interface we built for mysql, i'll show it with sql for WinForm ComboBox
the is for my comfort.
u can see the more simple example


Popular posts from this blog

c# Service Play Sound with NAudio example by Moshe

Asp.Net Ending Response options, Response.End() vs CompleteRequest()

JS/JQ simulate Enter event