title: selectedindexchanged on dynamically created gridview
body: <p>I've created a gridview dynamically, now i want to fire an event when the selectedindex has changed.</p>
  
  <pre><code> GridView NewDg = new GridView();
   NewDg.ID = "SubGridView" + e.Row.RowIndex.ToString();
   NewDg.DataKeyNames = new string[]{"logentry_id"};
   NewDg.SelectedIndexChanged += new EventHandler(NewDg_SelectedIndexChanged);
   NewDg.RowDataBound += new GridViewRowEventHandler(NewDg_RowDataBound);
  </code></pre>
  
  <p>The RowDataBound works but it doesn't produce the right postback URL i guess.
  In the RowDataBound i have the following code:</p>
  
  <pre><code>GridView sendingGridView = (GridView)sender;
  e.Row.Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(sendingGridView, "Select$" + e.Row.RowIndex);
  </code></pre>
  
  <p>this produces the following code:</p>
  
  <pre><code>javascript:__doPostBack('SubGridView4','Select$0')
  </code></pre>
  
  <p>Only this doesn't lead to the postback to this function:</p>
  
  <pre><code>        void NewDg_SelectedIndexChanged(object sender, EventArgs e)
      {
  
          GridView sendingGridView = (GridView)sender;
          ViewDetails(Convert.ToInt32(sendingGridView.SelectedDataKey["logentry_id"].ToString()));
      }
  </code></pre>
  
  <p>Does anyone know what i'm doing wrong?</p>