This is a migrated thread and some comments may be shown as answers.

how to change RowDetailsTemplate depend on retrieving data

1 Answer 82 Views
GridView
This is a migrated thread and some comments may be shown as answers.
mahdi gh
Top achievements
Rank 1
mahdi gh asked on 29 Jan 2012, 09:41 AM
Hi
I have a Gridview with RowDetailsTemplate. in RowDetailsTemplate i have three buttons, i want to hide or show each button based on user Permissions . my buttons are view/edit , delete, addToGroups and my news have different types which causes this scenario : in a list of news there are some news he can delete them and some news that he can't. there are some news he can view them and some news that he can't.
how should i hide the view or delete button for each row in gridview?
if i have to use RowDetailsSelectors,i had to define 9 templates? (3 buttons makes 3! different cases)
thanks
here is my gridview xaml:
<telerik:RadGridView x:Name="gridView" Width="840" HorizontalAlignment="Right" FlowDirection="RightToLeft" RowDetailsVisibilityMode="VisibleWhenSelected"
                 AutoGenerateColumns="False"
                 IsFilteringAllowed="False" RowIndicatorVisibility="Collapsed" CanUserDeleteRows="False" CanUserInsertRows="False"
                 CanUserSortColumns="False" ShowColumnHeaders="True" ShowGroupPanel="False" GridLinesVisibility="Horizontal" HorizontalContentAlignment="Right"
                 Margin="20,50,0,20" Grid.RowSpan="2" SelectionChanged="gridView_SelectionChanged" RowLoaded="gridView_RowLoaded" RowDetailsVisibilityChanging="gridView_RowDetailsVisibilityChanging">
                <telerik:RadGridView.Columns>
 
                    <telerik:GridViewDataColumn Header="عنوان خبر" IsReadOnly="True" Width="400" DataMemberBinding="{Binding Title}">
                    </telerik:GridViewDataColumn>
                    <telerik:GridViewDataColumn Header="تاریخ" IsReadOnly="True" DataMemberBinding="{Binding RegDate}">
                    </telerik:GridViewDataColumn>
                    <telerik:GridViewDataColumn Header="زمان" IsReadOnly="True" DataMemberBinding="{Binding RegTime}">
                    </telerik:GridViewDataColumn>
                    <telerik:GridViewDataColumn Header="وضعیت" IsReadOnly="True" DataMemberBinding="{Binding Status}" Width="185">
                    </telerik:GridViewDataColumn>
                    <telerik:GridViewDataColumn Header="پیوست" IsReadOnly="True" CellTemplateSelector="{StaticResource myCellTemplateSelector}" Width="Auto">
                    </telerik:GridViewDataColumn>
                    <telerik:GridViewDataColumn Header="حذف" IsReadOnly="True">
                        <telerik:GridViewDataColumn.CellTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Text="{Binding DelDate}" Foreground="{Binding IsDeleted, Converter={StaticResource MyConvertor}}" />
                                    <Button Name="btnBackFromDelete" Content="بازیابی" Tag="{Binding Path=NewsID}" Click="btnBackFromDelete_Click" />
                                    <Button Name="btnFullDelete" Content="حذف کامل" Tag="{Binding Path=NewsID}" Click="btnFullDelete_Click" />
                                </StackPanel>
                                 
                            </DataTemplate>
                        </telerik:GridViewDataColumn.CellTemplate>
                    </telerik:GridViewDataColumn>
                </telerik:RadGridView.Columns>
                <telerik:RadGridView.RowDetailsTemplate>
                    <DataTemplate>
                        <StackPanel Height="Auto" HorizontalAlignment="Left" Margin="10,10,0,0" Name="stackPanel1" VerticalAlignment="Top" Width="Auto" Orientation="Horizontal">
 
                            <TextBlock Text="{Binding Description}" VerticalAlignment="Center"  FontSize="14" Margin="5,0,0,0" Width="600" TextWrapping="Wrap"/>
                            <StackPanel Orientation="Horizontal" Margin="5,0,5,5">
                                <Button Name="btnEdit" Width="28" Height="28" Margin="5,0,0,0" Style="{StaticResource ButtonStyle1}" Tag="{Binding NewsID}" Click="btnEdit_Click">
                                    <Image Name="imgEdit" Width="24" Height="24" Source="/images/Copy%20of%20edit2.png"  ToolTipService.ToolTip="مشاهده و ویرایش" />
                                </Button>
                                <Button Name="btnDelete" Width="28" Height="28" Margin="5,0,0,0" Tag="{Binding NewsID}" Click="btnDelete_Click" Style="{StaticResource ButtonStyle1}" ToolTipService.ToolTip="حذف" >
                                    <Image Name="imgDelete" Width="24" Height="24" Source="/images/deletered.png" />
                                </Button>
                                <Button Name="btnAddToGroup" Width="28" Height="28" Margin="5,0,0,0" Style="{StaticResource ButtonStyle1}" ToolTipService.ToolTip="افزودن به گروه خبری" Tag="{Binding NewsID}" Click="btnAddToGroup_Click">
                                    <Image Name="imgGroup" Width="24" Height="24" Source="/images/add.png" />
                                </Button>
                            </StackPanel>
 
 
                        </StackPanel>
 
                    </DataTemplate>
                </telerik:RadGridView.RowDetailsTemplate>
            </telerik:RadGridView>

1 Answer, 1 is accepted

Sort by
0
mahdi gh
Top achievements
Rank 1
answered on 02 Feb 2012, 01:57 PM
Hi again
I Used code below for testing purpose but it doesn't work for the first time (sometimes even more times ). it doesn't has btnDelete in its children
private void gridView_RowDetailsVisibilityChanging(object sender, RowDetailsVisibilityChangingEventArgs e)
        {
            if (e.Row.ChildrenOfType<Button>().Count()>0)
            {
                foreach (Button btn in e.Row.ChildrenOfType<Button>())
                    if (btn.Name == "btnDelete")
                        btn.Visibility = System.Windows.Visibility.Collapsed;
            }
        }
Tags
GridView
Asked by
mahdi gh
Top achievements
Rank 1
Answers by
mahdi gh
Top achievements
Rank 1
Share this question
or