How to control each delete button on the every <li> tags. (asp.net) -Code behind
<p>I've been trying to write an onclick function, but I couldn't figure out how to do it. I wrote a function in page load() and it provides that when the pages loading, the data is coming from database. And that <code>&lt;li&gt;</code> and delete <code>buttons</code> creating right there. I mean I didn't write <code>&lt;li&gt;</code> or button tags. (You can see the structure on the screen shot, I'll share it here). I can insert the records, but now I need to delete it on that delete buttons.</p>

<p>In this case my problem is: I want to use an onclick function in code behind (or you can advice another way) which I can control that <code>&lt;li&gt;</code> (like selectedrow) and anchor <code>&lt;a&gt;</code>.</p>

<p>This is page load (creating <code>&lt;li&gt;</code>,<code>&lt;a&gt;</code> and <code>button</code>)</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>for (int i = 0; i &lt; db.machines.Length; i++) {
  li = new HtmlGenericControl("li");
  ancor = new HtmlGenericControl("a");
  btn = new Button();
  btn.Text = "Delete";
  btn.Attributes.Add("runat", "server");
  btn.Attributes.Add("class", "deleteButton");
  li.Controls.Add(btn);
  li.Attributes.Add("class", "list-group-item");
  newitem = db.machines[i];
  machineUl.Controls.Add(li);
  ancor.InnerText = newitem;
  li.Controls.Add(ancor);
}</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div id="machineListId" class="panel"&gt;
  &lt;ul id="machineUl" class="list-group" runat="server"&gt;

  &lt;/ul&gt;
&lt;/div&gt;</code></pre>
</div>
</div>
</p>

<p>Here is the screen shot</p>

<p><a href="https://i.stack.imgur.com/bkMXi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bkMXi.png" alt=""></a></p>