Click here to Skip to main content
15,743,299 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello everyone,

I am making one application in WPF in which there is a window inside which it has a stackpanel. Now when i fetch list of students from database there are many students.. now i have created one user control which is generated for each and every student and placed into stackpanel !!

Now in that user control it is populated with Student Name, Mobile Number and there are two buttons namely "Edit" and "Delete"..

Now the window looks like this..

Student 1 Edit Delete

Student 2 Edit Delete


now i have generated only one field and it is called many times .. now what i need is when i click Edit or Delete Button specific student on which the button is clicked should be edited or deleted.....

Please let me know how could i make this possible...

Thanks & Regards,
Krunal Panchal
Posted
Comments
Andy411 12-Mar-12 11:04am    
Well, it's not a solution, just a suggestion. For me it looks like, that you should think about a GridView populated with the students instead of creating a user control for each student. But maybe I'm missing something in your description and you have a good reason for your way.

1 solution

Use tag.

If you have many objects as Student (For example student1, student2, ...)

Set the tag of buton = specific student when the buttons are being generated.

for example:

C#
Edit1.Tag = student1;
Delete1.Tag = student1;

Edit2.Tag = student2;
Delete2.Tag = student2;


Now, when you click on edit or delete, then you know that which button is clicked.

In Button_Click event:
C#
Student selectedItem = (Student)sender;
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900