How to get the ID to delete this item from the table?
<p>I am trying to develop a dynamic table where the user can add a new row directly. I have a probelm now in the code-behind for getting the ID of the inserted question but I don't know how to get it. So how to get it? </p>

<p>FYI, the database design that I have is as following:
Question Table: QuestionID, Question, QuestionOrder, AnswerExplanation</p>

<p>ASP.NET Code:</p>

<pre><code>&lt;asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="true" UpdateMode="Conditional"&gt;
        &lt;ContentTemplate&gt;
        &lt;asp:Table ID="questionsList" runat="server" Width="50%" CellPadding="0" CellSpacing="0"
                    style="border:2px solid #003366; font-size:17px; font-weight:bold;"&gt;
        &lt;/asp:Table&gt;

        &lt;asp:Table ID="Table1" runat="server" Width="50%" CellPadding="0" CellSpacing="0"
                    style="border:2px solid #003366;"&gt;
            &lt;asp:TableFooterRow&gt;
                &lt;asp:TableCell&gt;Add&lt;/asp:TableCell&gt;
                &lt;asp:TableCell&gt;
                    &lt;asp:TextBox ID="txtQuestion" runat="server"&gt;&lt;/asp:TextBox&gt;
                    &lt;ajaxToolkit:TextBoxWatermarkExtender ID="TBWE" runat="server"
                                    TargetControlID="Question" WatermarkText="Type the Question here"
                                    WatermarkCssClass="watermarked"&gt;
                    &lt;/ajaxToolkit:TextBoxWatermarkExtender&gt;
                &lt;/asp:TableCell&gt;
                &lt;asp:TableCell&gt;
                    &lt;span style="margin:3px 10px 0px 0px;"&gt;
                        &lt;asp:ImageButton ID="addButton" runat="server" ImageUrl="Images/tick_small.png" OnClick="addQuestion" /&gt;
                    &lt;/span&gt;
                &lt;/asp:TableCell&gt;
            &lt;/asp:TableFooterRow&gt;
        &lt;/asp:Table&gt;
        &lt;/ContentTemplate&gt;
    &lt;/asp:UpdatePanel&gt; 
</code></pre>

<p>Code-Behind:</p>

<pre><code>public void fill_Questions()
    {
        string connString = ConfigurationManager.ConnectionStrings["QuizSysDBConnectionString"].ConnectionString;
        SqlConnection conn = new SqlConnection(connString);
        string selectQuery = "SELECT * FROM Questions";
        SqlCommand cmd = new SqlCommand(selectQuery, conn);
        DataSet ds = new DataSet();
        SqlDataAdapter sda = new SqlDataAdapter();
        sda.SelectCommand = cmd;

        Table table = (Table)UpdatePanel1.FindControl("questionsList");
        try
        {
            //open the connection
            conn.Open();
            //filling the dataset with the data
            sda.Fill(ds);
            //close the connection
            conn.Close();
        }
        catch
        {
            table.Rows.Clear();
        }


        //Loading the data into the table
        if (ds.Tables.Count &gt; 0)
        {
            int rowsNum = ds.Tables[0].Rows.Count;
            for (int i = 0; i &lt; rowsNum; i++) 
            {
                TableRow row = new TableRow();
                table.Rows.Add(row);

                for (int colCount = 0; colCount &lt; 4; colCount++)
                {
                    TableCell cell = new TableCell();
                    row.Cells.Add(cell);

                    if (colCount == 0)
                    {
                        int n = i + 1;
                        cell.Controls.Add(new LiteralControl(n.ToString()));
                    }
                    else if (colCount == 1)
                    {
                        cell.Controls.Add(new LiteralControl(ds.Tables[0].Rows[i]["Question"].ToString()));
                    }
                    else if (colCount == 2)
                    {
                        cell.Controls.Add(new LiteralControl(ds.Tables[0].Rows[i]["QuestionOrder"].ToString()));
                    }
                    else if (colCount == 3)
                    {
                        cell.Controls.Add(new LiteralControl(ds.Tables[0].Rows[i]["AnswerExplanation"].ToString()));
                    }
                    else if (colCount == 4)
                    {
                        ImageButton deleteButton = new ImageButton();
                        deleteButton.ImageUrl = "Images/DeleteRed.png";
                        deleteButton.ID = ds.Tables[0].Rows[i]["Question"].ToString() + "_" + i;
                        deleteButton.Click += new ImageClickEventHandler(deleteQuestion);
                        cell.Controls.Add(deleteButton);

                    }
                } //End for loop
            }//End OUTER for loop

        }//End if statement

    }


    //For deleting question
    public void deleteQuestion(object sender, EventArgs e) 
    {
        //int id = System.Convert.ToInt32((ImageButton)sender.ToString().Split()[0]);
        try 
        {
            string connString = ConfigurationManager.ConnectionStrings["QuizSysDB"].ConnectionString;
            SqlConnection conn = new SqlConnection(connString);
            string deleteQuery = "DELETE FROM Question WHERE ID = @id";
            SqlCommand cmd = new SqlCommand(deleteQuery,conn);
            cmd.Parameters.AddWithValue("@id", ID);
            conn.Open();
            cmd.ExecuteNonQuery();
            conn.Close();
            fill_Questions();
        }
        catch(SqlException se){}
    }
</code></pre>

<p>My problem now is exactly with the following line inside the deleteQuestion method:</p>

<pre><code> //int id = System.Convert.ToInt32((ImageButton)sender.ToString().Split()[0]);
</code></pre>
