我使用listview包含gridview来绑定数据。我想在按钮点击事件中找到复选框控件(即chkUser)。 (即btnUserId点击事件)
我怎么能实现它?如果这是其他任何替代解决方案,请告诉我。
我的代码:
<ListView Name="listUsers" SelectionMode="Single" Height="200" SelectionChanged="listUsers_SelectionChanged">
<ListView.View>
<GridView AllowsColumnReorder="true">
<GridViewColumn Header="User Id" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<Button Name="btnUserId" Cursor="Hand" Tag="{Binding Path=UserId }" Click="btnUserId_Click" Content="{Binding Path=UserId }" Style="{StaticResource LinkButton}"></Button>
</DataTemplate>
</GridViewColumn.CellTemplate>
</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="User Type" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<Label Name="lblUserType">User Type</Label>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Active" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<CheckBox Name="chkUser" Width="120" Content="{Binding Path=deleted }"></CheckBox>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Update" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<Button Height="23" Name="button1" Tag="{Binding Path=UserId }" CommandParameter="{ Binding Path=UserId }" Click="button1_Click" Width="75">Button</Button>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
答案 0 :(得分:1)
您应该能够使用FindName按名称查找ctrl。在上面的例子中,它将是
listUsers.FindName("chkUser");
干杯