Standard Data Template

4 posts, 0 answers
  1. christina noel
    christina noel avatar
    42 posts
    Member since:
    Mar 2010

    Posted 26 Sep 2011 Link to this post

    I'm just starting on using the Silverlight RadGridView, and have come across a puzzle. Our standard of behavior in the Ajax RadGrid is to allow the rows of the grid to be "click to select" for the purposes of functions in the grid (delete, copy, etc.), but to have the text or image of each cell be a LinkButton or ImageButton that will open a new web page allowing the edit of the item shown in the grid. I need to mimic this functionality in the radgridview as closely as possible. Here's the way I'm currently doing that:

    <telerik:RadGridView x:Name="grdFiles" SelectionMode="Extended" telerik:StyleManager.Theme="Office_Blue"
                                 AutoGenerateColumns="false" ItemsSource="{Binding Source={StaticResource FolderSource}, Path=Files}"
                                 RowLoaded="grdFiles_RowLoaded" SelectionChanging="grdFiles_SelectionChanging" RowIndicatorVisibility="Collapsed" FrozenColumnCount="3" CanUserFreezeColumns="false"  >
                <telerik:RadGridView.Columns>
                    <telerik:GridViewSelectColumn UniqueName="SelectColumn" />
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding FileVersionOID}" Header="ID" IsReadOnly="True" />
                        <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}"   Header="Name" IsReadOnly="True" MaxWidth="250">
                            <telerik:GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <HyperlinkButton ClickMode="Press" Foreground="Black" Click="HyperlinkButton_Click" Content="{Binding Name}" CommandParameter="{Binding}" HorizontalAlignment="Left" />
                                </DataTemplate>
                            </telerik:GridViewColumn.CellTemplate>
                        </telerik:GridViewDataColumn>
                        <telerik:GridViewDataColumn DataMemberBinding="{Binding IsFavorite}" Header="Favorite" IsReadOnly="True"   >
                            <telerik:GridViewDataColumn.CellTemplate>
                                <DataTemplate>
                                    <HyperlinkButton Click="HyperlinkButton_Click" CommandParameter="{Binding}" Visibility="{Binding IsFavorite, Converter={StaticResource VisibilityConverter}}" HorizontalContentAlignment="Center" >
                                        <Image Source="images/Favorite_Small.png"  />
                                    </HyperlinkButton>
                                </DataTemplate>
                            </telerik:GridViewDataColumn.CellTemplate>
                        </telerik:GridViewDataColumn>
                       <telerik:GridViewDataColumn DataMemberBinding="{Binding Description}" Header="Description" IsReadOnly="true" TextWrapping="Wrap" MaxWidth="250" >
                            <telerik:GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <HyperlinkButton ClickMode="Press" Foreground="Black" Click="HyperlinkButton_Click" Content="{Binding Description}"  CommandParameter="{Binding}" HorizontalAlignment="Left"/>
                                </DataTemplate>
                            </telerik:GridViewColumn.CellTemplate>
                        </telerik:GridViewDataColumn>
       
                </telerik:RadGridView.Columns>
            </telerik:RadGridView>

    The major problem I have is that I've got about 30 more text columns to make, and I would like to find a way to make the DataTemplate a static resource that takes its content from whatever the column would have displayed by default. Is there any way to do this? I'll mess with the default style, or even the theme if I have to to make this work right.

    --Christina

    P.S. I looked at Hyperlink columns, but as far as I can tell they assume you're navigating directly to a URL, which doesn't work right for this since we need to save state and do some setup in the "Hyperlink_Click" function before we can actually go. If the Hyperlink columns CAN actually go to a function instead of direct to the URL, that's definitely an acceptable solution and I'd appreciate pointers on how to make it work.
  2. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1216 posts

    Posted 29 Sep 2011 Link to this post

    Hi Christina Noel,

    Unfortunately such an approach might be in contradiction with Silverlight good development practices, or even hit some framework limitations (opening new browser windows, in order to edit your data there). Please, let me propose you these two examples that illustrate how to edit RadGridView's data using the RadDataForm control:
    GridViewEditWithDataForm 
    DataFormICollectionViewSynchronization
    In case this solution does not meet your requirements, we would highly appreciate to recieve some more information on the behavior that you aim to achieve, so that we could think of an alternative approach.

    Best wishes,
    Ivan Ivanov
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
  3. christina noel
    christina noel avatar
    42 posts
    Member since:
    Mar 2010

    Posted 30 Sep 2011 Link to this post

    Unfortunately, the requirement of opening another page is fixed.

    Here's some more information:

    1. We are creating a "file explorer" experience, as you might have guessed from the name of the datasource. The file structure we are exploring does not exist anywhere, but is instead a construct of our database (including the files themselves, which are stored in the db).
    2. We are replacing our old asp.net file explorer with an SL file explorer, and have to keep all previously existing functionality while adding new bells and whistles. The only new feature of relevance is that the SL file explorer is in a child window (javascript window.open) of the main app instead of in the same window.
    3. The asp.net file explorer, like most of the rest of our application, consisted of a RadGrid with selectable rows. You can select multiple rows for the purposes of deletion, copy, download, and a few other internal functions. If you clicked on any of the text fields (name, size, description, etc.), it would call an internal function which set up several session variables and then redirected you to "Maintain File" for the selected row. Maintain File would let you edit a LOT of details, upload a new version of the file, change the internal permissions on the file, and many other things.
    4. Moving Maintain File into SL is not in scope of the current development.
    5. I have made it possible for SL to open Maintain File in the main app window (via javascript window.opener.open function), and the datatemplate of the columns that I already sent you can correctly call the SL code-behind function (Hyperlink_Click) that does some double-checking and clean up and then invokes the javascript function -- and opens Maintain File in the main app window.

    I'm just asking you if there's someway to keep from having to copy that datatemplate over and over, each time changing the "content" binding of the hyperlink, when the data to be displayed is exactly the same as GridMemberBinding. Or, alternatively, some way of making the HyperlinkColumn call the SL code-behind function so that I can open Maintain File.

    --Christina
  4. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1216 posts

    Posted 05 Oct 2011 Link to this post

    Hello Christina Noel,

    Please, excuse me for the late reply. I would advise you to utilize a custom column that inherits from GridViewDataColumn. This approach will prevent you from setting the same DataTemplate multiple times or using converters. Try overriding CreateCellElement and define the HyperLinkButton there. In this way you will be able to reuse the DataMemberBinding value. Please, do not hesitate to contact us if any further inquiries occur.

    Greetings,
    Ivan Ivanov
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
Back to Top