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)       
{
  try            
  {
      DataTable tbl = mysql.ExecuteSelect(query);                
      ddl.DataSource = tbl;                
      ddl.DataTextField = strText;                
      ddl.DataValueField = srtValue;                
      ddl.DataBind();                
      ListItem li = new ListItem();
      if (string.Empty.Equals(strHeader))
          li.Text = "Choose";
      else                    
          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
http://bresleveloper.blogspot.com/2012/05/dynamic-fill-combobox-winform-example.html

Comments

Popular posts from this blog

c# Service Play Sound with NAudio example by Moshe

SOLVED The item could not be indexed successfully because the item failed in the indexing subsystem

JS/JQ simulate Enter event