c# - Find the content of a TextBox inside a DataTemplate with multiple rows -


i have code:

<stackpanel> <itemscontrol itemssource="{binding position}">     <itemscontrol.itemtemplate>         <datatemplate>             <grid>                 <grid.columndefinitions>                     <columndefinition width="2*" />                     <columndefinition width="*" />                     <columndefinition width="*" />                     <columndefinition width="*" />                     <columndefinition width="80" />                 </grid.columndefinitions>                 <textbox grid.column="0" text="{binding name}" margin="5" />                 <textbox grid.column="3" text="{binding id}" margin="5" />                 <button grid.column="4" content="x" click="delete" />             </grid>         </datatemplate>     </itemscontrol.itemtemplate> </itemscontrol> 

for example have 3 rows. want delete second row it's elements. click delete button in second row , need id inside textbox. if id in code behind can delete position database. there no problem if have 1 row. in case give name textbox containing id , can value in code behind. how can if have 3,4,10 positions each of them in separate row?

you may bind button's tag id property , access in click handler:

<button grid.column="4" content="x" click="delete" tag="{binding id}" /> 

click handler:

private void delete(object sender, routedeventargs e) {     var button = (button)sender;     var id = (int)button.tag;     // ... } 

Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -