html - How to control each delete button on the every <li> tags. (asp.net) -Code behind -


i've been trying write onclick function, couldn't figure out how it. wrote function in page load() , provides when pages loading, data coming database. , <li> , delete buttons creating right there. mean didn't write <li> or button tags. (you can see structure on screen shot, i'll share here). can insert records, need delete on delete buttons.

in case problem is: want use onclick function in code behind (or can advice way) can control <li> (like selectedrow) , anchor <a>.

this page load (creating <li>,<a> , button)

for (int = 0; < 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);  }
<div id="machinelistid" class="panel">    <ul id="machineul" class="list-group" runat="server">      </ul>  </div>

here screen shot

for(yourconditions) {    //add button    var button = new button {id = "buttonid", text = "text"};   button.click += button_click;   li.controls.add(button) } 

code behind function

private void button_click(object sender, eventargs e) {     //get id of calling button        button button = (button)sender;        string buttonid = button.id;     // next stuff } 

//note: make button id unique in loop. hope helps!


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -