Tuesday, May 8, 2012

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

No comments:

Post a Comment