Find the value of control inside the datatemplate of datagrid in silverlight
Hi,
i am having one datagrid . i am binding data to that grid. in that grid i am having one column in that column i took one hyperlinkbutton called TakeExam in datatemplate. i am having employeeid column in that datagrid. now when i click on hyperlink i have to get the employee id of perticular row . i am sending my source code and xaml.cs file too.can anybody help me
<sdk:DataGrid Grid.Row="2" Grid.Column="1" x:Name="Grd_AssessmentDetails" VerticalAlignment="Center" LoadingRow="Grd_AssessmentDetails_LoadingRow" SelectedItem="{Binding SelectedItem, Mode=OneWay}" RowDetailsVisibilityMode="VisibleWhenSelected" SelectionMode="Single" AutoGenerateColumns="False" HorizontalContentAlignment="Center" HorizontalGridLinesBrush="Goldenrod" HorizontalAlignment="Center" VerticalScrollBarVisibility="Disabled" SelectionChanged="dgQPGallery_SelectionChanged" Grid.ColumnSpan="4" Width="900">
<sdk:DataGrid.Resources>
<Style TargetType="sdk:DataGridColumnHeader">
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="FontSize" Value="10"/>
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<TextBlock Text="{Binding}" TextWrapping="Wrap" MinWidth="50"/>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</sdk:DataGrid.Resources>
<sdk:DataGrid.Columns>
<sdk:DataGridTemplateColumn Header="SNo" Width="45">
<sdk:DataGridTemplateColumn.CellTemplate>
<DataTemplate x:Name="SNo">
<TextBlock x:Name="tbID"></TextBlock>
</DataTemplate>
</sdk:DataGridTemplateColumn.CellTemplate>
</sdk:DataGridTemplateColumn>
<sdk:DataGridTemplateColumn Header="AllotedExamID" Width="45" Visibility="Collapsed">
<sdk:DataGridTemplateColumn.CellTemplate>
<DataTemplate x:Name="AllotedExamid">
<sdk:Label x:Name="lbl_AllotedExamid" Content="{Binding AllotedExamID,Mode=TwoWay}"></sdk:Label>
</DataTemplate>
</sdk:DataGridTemplateColumn.CellTemplate>
</sdk:DataGridTemplateColumn>
<sdk:DataGridTextColumn Header="TYPE" Width="80" Binding="{Binding ExamType}"/>
<sdk:DataGridTextColumn Header="CODE" Width="55" Binding="{Binding QPCodeString}"/>
<sdk:DataGridTextColumn Header="TITLE" Width="80" Binding="{Binding QPTitle}"/>
<sdk:DataGridTextColumn Header="QUESTIONS" Width="55" Binding="{Binding Total_Questions}"/>
<sdk:DataGridTextColumn Header="DURATION" Width="55" Binding="{Binding Total_Time}"/>
<sdk:DataGridTextColumn Header="START DATE" Width="80" Binding="{Binding FromDate}"/>
<sdk:DataGridTextColumn Header="END DATE" Width="80" Binding="{Binding ToDate}" />
<sdk:DataGridTextColumn Header="START TIME" Width="55" Binding="{Binding FromTime}" />
<sdk:DataGridTextColumn Header="END TIME" Width="55" Binding="{Binding ToTime}"/>
<sdk:DataGridTextColumn Header="ASSAIGNED ON" Width="80" Binding="{Binding PostedDate}"/>
<sdk:DataGridTextColumn Header="BY" Width="55" Binding="{Binding EmployeeName}"/>
<sdk:DataGridTextColumn Header="STATUS" Width="60" Binding="{Binding Status}"/>
<sdk:DataGridTemplateColumn Header="EXAM" Width="55" >
<sdk:DataGridTemplateColumn.CellTemplate>
<DataTemplate x:Name="EXAM">
<HyperlinkButton Content="TakeExam" x:Name="Hpl_TakeExam" Click="Hpl_TakeExam_Click" />
<!--<TextBlock x:Name="tbID"></TextBlock>-->
</DataTemplate>
</sdk:DataGridTemplateColumn.CellTemplate>
</sdk:DataGridTemplateColumn>
<!--<sdk:DataGridTextColumn Header="EXAM" Width="100" Binding="{Binding QPStatus}" />-->
</sdk:DataGrid.Columns>
</sdk:DataGrid>
private void Hpl_TakeExam_Click(object sender, RoutedEventArgs e)
{
foreach (Assessment assesment in Grd_AssessmentDetails.ItemsSource)
{
FrameworkElement ele = Grd_AssessmentDetails.Columns[columnindex].GetCellContent(assesment);
Label allotedexamid = ele.FindName("lbl_AllotedExamid") as Label;
allotedexamid.Content = assesment.AllotedExamID;
}
Thanks
P.Nagaraju.