Q: In widget, the value of select field doesn't get updated, changes after saving I'm building a simple widget which will allow the user to select a post among a list of posts.
For some reason, when I select an option, I believe it actually gets selected but the option doesn't remain in the select field.  
I think my error is at the following line but I don't manage to fix it. Maybe calling the_ID is not the way to do it...:
<option value="<? echo the_ID(); ?>" <?php selected(the_ID(), $instance['post_to_display']); ?>><?php the_title(); ?></option>

Here is my code:
class Simple_Widget extends WP_Widget{

  function Simple_Widget() {
    $widget_ops = array(
      'classname' => 'w_reports',
      'description' => __('Use this widget to add a post to the sidebar', 'theme'));
    $this->WP_Widget('w_reports', __('Simple_Widget', 'roots'), $widget_ops);
  }

  function widget($args, $instance) {
    extract( $args );
    $post_to_display = $instance['post_to_display'];     
  }

  function update($new_instance, $old_instance) {
    $instance['post_to_display'] = $new_instance['post_to_display'];
    return $instance;
  }

  function form($instance) {
  ?>
    <p>
      <label for="<?php echo $this->get_field_id('post_to_display'); ?>">Choose a post to display:</label> 
      <select id="<?php echo $this->get_field_id('post_to_display'); ?>" name="<?php echo $this->get_field_name('post_to_display'); ?>" class="widefat">

      <?php // My query
        $the_query = new WP_Query( 'post_type=my-post' );
        while ( $the_query->have_posts() ) : $the_query->the_post();
      ?>
      <option value="<? echo the_ID(); ?>" <?php selected(the_ID(), $instance['post_to_display']); ?>><?php the_title(); ?></option>

      <?php endwhile;
      wp_reset_postdata();
      ?>
     </select>
  </p>

  // Just a test    
  <?php echo $instance['post_to_display']; ?>


What am I doing wrong?
Thanks in advance for your help!

A: Use get_the_ID() instead of the_ID(). the_ID() will echo'ed the ID of posting:
<option value="<? the_ID(); ?>" <?php selected(get_the_ID(), $instance['post_to_display']); ?>><?php the_title(); ?></option>


A: For some reason, this (found here) works. However, I still haven't managed to adapt it to do what I want to do. Therefore, this answers only partially my question. 
<select id="<?php echo $this->get_field_id('posttype'); ?>" name="<?php echo $this->get_field_name('posttype'); ?>" class="widefat" style="width:100%;">
  <?php foreach(get_post_types($getposttype_args,'names') as $post_type) { ?>
    <option <?php selected( $instance['posttype'], $post_type ); ?> value="<?php echo $post_type; ?>"><?php echo $post_type; ?></option>
  <?php } ?>      
</select>

