title: passing a parameter from a ImageButton to code behind
body: <p><strong>EDITED QUESTION</strong></p>
  
  <p>I want to pass a variable, in this case 'name' containing the string bill, to a code behind method and use debug.print to see it</p>
  
  <pre><code>string name = "bill";
  &lt;asp:ImageButton runat="server" id="DeleteButton"  ImageUrl="Images/delete.jpg" 
  CommandArgument='&lt;%# Eval("name") %&gt;' CommandName="ThisBtnClick" text="Delete Me" onclick="DeleteMonth" /&gt; 
  </code></pre>
  
  <p>I've tried:</p>
  
  <pre><code>CommandArgument='&lt;%# Eval("name") %&gt;'
  CommandArgument='&lt;%# Bind("name") %&gt;'
  CommandArgument='&lt;%= "name" %&gt;
  </code></pre>
  
  <p>This is my print function</p>
  
  <pre><code>protected void DeleteMonth(object sender, EventArgs e)
  {
      ImageButton btn = (ImageButton)sender;
        switch (btn.CommandName)
      {
          case "ThisBtnClick":
              Debug.Print("--" + btn.CommandArgument.ToString());
              break;
          case "ThatBtnClick":
              break;
      }
  }
  </code></pre>
  
  <p>I think i need to databind something first but honestly I have no idea. I just get a blank when i print. Has anyone dealt with this before</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>What I want to do is dynamically create a table. the name variable gets pulled from a database and then creates a table based on that name. I want the last column of the table to be an X so i can delete everything in that row. I'm using an imagebutton. here's my code</p>
  
  <pre><code>using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(sqlConnectionString))
      {
          conn.Open();
          string query = "SELECT * FROM dbo.Archive";
          System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(query, conn);
          System.Data.SqlClient.SqlDataReader rdr = cmd.ExecuteReader();
  
          while (rdr.Read())
          {
              string name, created, 1Updated, 2Updated, 3Updated;
              name = rdr.GetString(1);                    // name of month
              if (!(rdr.IsDBNull(2)))                     // checks date for a null value
              { created = rdr.GetDateTime(2).ToString(); }// if not null date is turned into a string and saved in a variable
              else
              { created = "---"; }                        // else date is given a default value
              if (!(rdr.IsDBNull(3)))
              { 1Updated = rdr.GetDateTime(3).ToString(); }
              else
              { 1Updated = "---"; }
              if (!(rdr.IsDBNull(4)))
              { 2Updated = rdr.GetDateTime(4).ToString(); }
              else
              { 2Updated = "---"; }
              if (!(rdr.IsDBNull(5)))
              { 3Updated = rdr.GetDateTime(5).ToString(); }
              else
              { 3Updated = "---"; }
  
              Response.Write("&lt;tr&gt;&lt;td&gt;" + name + "&lt;/td&gt;");
              Response.Write("&lt;td&gt;" + created + "&lt;/td&gt;");
              Response.Write("&lt;td&gt;" + 1Updated + "&lt;/td&gt;");
              Response.Write("&lt;td&gt;" + 2Updated + "&lt;/td&gt;");
              Response.Write("&lt;td&gt;" + 3Updated + "&lt;/td&gt;");
              Response.Write("&lt;td&gt;&lt;a&gt;1&lt;/a&gt;&lt;/td&gt;");
              Response.Write("&lt;td&gt;&lt;a&gt;2&lt;/a&gt;&lt;/td&gt;");
              Response.Write("&lt;td&gt;&lt;a&gt;3&lt;/a&gt;&lt;/td&gt;");
              Response.Write("&lt;td&gt;&lt;a&gt;Compliance Summary&lt;/a&gt;&lt;/td&gt;");
  
              Response.Write("&lt;td align = 'center'&gt;"+name);%&gt; 
              &lt;asp:ImageButton runat="server" id="DeleteButton"  ImageUrl="Images/delete.jpg" 
              CommandArgument='&lt;%# Eval("name") %&gt;' CommandName="ThisBtnClick" text="Delete Me" onclick="DeleteMonth" /&gt; 
              &lt;% Response.Write("&lt;/td&gt;&lt;/tr&gt;");
          }     
  </code></pre>