Bind Enum data type in dropdown list

February 10, 2014

Hello,

Here is a code snippet for bind enum data type in drop down list with datasource property.


var enumerationType = typeof(Entity.ProgramType);
 var dictionary = new Dictionary<int, string>();

foreach (int value in Enum.GetValues(enumerationType))
 {
 var name = Enum.GetName(enumerationType, value);
 dictionary.Add(value, name);
 }
 ddlProgramType.DataSource = dictionary;
 ddlProgramType.DataTextField = "value";
 ddlProgramType.DataValueField = "key";
 ddlProgramType.DataBind();
 ddlProgramType.Items.Insert(0, new ListItem("---Both---", "0"));

you will get your dropdown binded with enum 🙂


Split string with multi-delimiter with asp.net c#

February 10, 2014

Hello,

Here is a trick for split string by another string

Or we can call split string by multi delimiter.


string data = "THExxQUICKxxBROWNxxFOX";

return data.Split(new string[] { "xx" }, StringSplitOptions.None);

this code returns you array by split main string with “xx”.