I am using listview contain gridview to bind the data.
How I can use CommandParameter present on button from my .cs file. The button is present inside my gridview. Also how to identity each row by id from my .cs file on button click event.
My code:
<ListView Name="listUsers" SelectionMode="Single" Height="200" SelectionChanged="listUsers_SelectionChanged">
<ListBoxItem></ListBoxItem>
<ListView.View>
<GridView AllowsColumnReorder="true">
<GridViewColumn Header="User Id" DisplayMemberBinding="{ Binding Path=UserId }"></GridViewColumn>
<GridViewColumn Header="Name" DisplayMemberBinding="{ Binding Path=UserName }"></GridViewColumn>
<GridViewColumn Header="Email Id" DisplayMemberBinding="{ Binding Path=Email }"></GridViewColumn>
<GridViewColumn Header="Mobile" DisplayMemberBinding="{ Binding Path=Mobile }"></GridViewColumn>
<GridViewColumn Header="Update" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<Button Height="23" Name="button1" CommandParameter="{ Binding Path=UserId }" Click="button1_Click" Width="75">Button</Button>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
You’ll need to create a
Command(subclass ofICommand) and set your button command attribute to it.You are using a click event, so i doubt the command parameter will be available when you handle the event.
if you are only interested in this UserId field and not other features of Command (like CanExecute etc), you can just use the Tag property of the button as you can get this via the code behind.
In your button1_click event you can just access