views:

67

answers:

3

hi, i have created a dynamic row which contains 2 labels, 2 textboxes and 2 buttons- Add & Remove and I want to add new rows of same content using dynamicaly created Add Buttons and remove same row using dynamicaly created Remov buttons, i am using C# please help me out.

A: 

is your problem the event handling? You may add event handlers this way:

yourButton.OnClick += new EventHandler(yourEventHandlingMethod);

private void yourEventHandlingMethod(Object sender, EventArgs e)
{
   // handling stuff
}

not sure if everything is literal as i got no visual studio available currently. check the formfiles created by VS when adding a button to a form.

with the argument sender you're able to know the object that has received the event,

regards

Atmocreations
A: 

Have you tried using a DataGridView and configuring a Row Template for it?

MoMo
A: 

If you are using ASP.NET you might try using the paradigm of "one add button" and "many remove buttons". The way in which you do that is (summarized)

  • Statically add the label, textbox and "add" button to the form using html markup or the designer.
  • In the page init event create a list of remove buttons assigning them to an event handler.
  • Create a routine to display the list of items with remove buttons. When the remove buttons are displayed assign an "ID" to them like "btnRemove_1234" where 1234 is the database id of the element you are removing.
  • In the remove button event handler parse the "ID" of the sender obtaining the id of the item you want to remove from the list. remove the item and redisplay the list.