我有一个DataGrid
显示几个名册信息的Employees
. 我添加了一个带有CheckBox
. 我想从选定(选定)行KeyIDs
的所有行中获取(从数据库绑定)。CheckBox
这些KeyIDs
我必须传递给 SQL 以删除选定的行 ( BtnDeleteSelected_Click
)。请帮忙。
这是我的DataGrid
:
<DataGrid AutoGenerateColumns="False" Grid.Row="1" Height="555" HorizontalAlignment="Left" Margin="0,5,0,0" Name="dgRosterList" VerticalAlignment="Top" Width="980" ItemsSource="{Binding}" SelectionMode="Single" SelectionUnit="FullRow" CanUserResizeColumns="True" CanUserSortColumns="True" AlternatingRowBackground="Gainsboro" AlternationCount="2" IsEnabled="True" Grid.ColumnSpan="2">
<DataGrid.Columns>
<DataGridTemplateColumn Width="30">
<DataGridTemplateColumn.HeaderTemplate>
<DataTemplate>
<CheckBox x:Name="all" Content="" Click="CheckBox_Click"/>
</DataTemplate>
</DataGridTemplateColumn.HeaderTemplate>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<CheckBox Checked="chkSelect_Checked" Name="chkSelect"></CheckBox>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Header="Sl No" Binding="{Binding SlNo}"/>
<DataGridTextColumn Header="Key ID" Binding="{Binding KeyID}" Width="80" Visibility="Hidden"/>
<DataGridTextColumn Header="Emp ID" Binding="{Binding Emp_ID}" Width="80"/>
<DataGridTextColumn Header="Emp Name" Binding="{Binding Emp_Name}" Width="200"/>
<DataGridTextColumn Header="Date" Binding="{Binding PDate, StringFormat={}{0:dd/MM/yyyy}}" Width="100"/>
<DataGridTextColumn Header="Shift" Binding="{Binding Shift_Code}" Width="80"/>
<DataGridTextColumn Header="In Time" Binding="{Binding InTime, StringFormat={}{0:hh:mm}}" Width="80"/>
<DataGridTextColumn Header="Out Time" Binding="{Binding OutTime, StringFormat={}{0:hh:mm}}" Width="80"/>
<DataGridTemplateColumn Header="Half Day" Width="80">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Image Name="IsHalfDay" Width="15" Height="15" Source="" />
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding HalfDay}" Value="Yes">
<Setter TargetName="IsHalfDay" Property="Source" Value="../Images/ico_tick.gif"/>
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="Off Day" Width="80">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Image Name="IsOffDay" Width="15" Height="15" Source="" />
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding OffDay}" Value="Yes">
<Setter TargetName="IsOffDay" Property="Source" Value="../Images/ico_tick.gif"/>
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="Delete" Width="75">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Name="btnDelete" Click="btnDelete_Click" Width="50" Height="20" ToolTip="Delete Roster" CommandParameter="{Binding Path=KeyID}" >
<Image Source="../Images/delete.png" Width="15" Height="19"/>
</Button>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Header="Processed" Binding="{Binding Processed}" Visibility="Hidden"/>
</DataGrid.Columns>
<DataGrid.RowDetailsTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<!--<Image Source="{Binding XPath=media:thumbnail/@url}"
Width="60" Height="60"/>-->
<TextBlock Text="{Binding Path=WeeklyOffs}"/>
</StackPanel>
</DataTemplate>
</DataGrid.RowDetailsTemplate>
</DataGrid>