我正在使用 listview 包含 gridview 来绑定数据。如何使用 .cs 文件中按钮上的 CommandParameter。该按钮出现在我的网格视图中。此外,如何在按钮单击事件中通过 .cs 文件中的 id 标识每一行。
我的代码:
<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>