Telerik Forums
UI for ASP.NET AJAX Forum
2 answers
101 views

Requirements

RadControls version

2009Q3

.NET version

ALL

Visual Studio version

ALL

programming language

C#

browser support

all browsers supported by RadControls


PROJECT DESCRIPTION

A strategy for building a Section 508/WCAG Telerik radGrid page

Accessibility and translations can often result in a medusa head for code. On one hand you want a feature rich grid but you are constrained by Section 508.  Managing and tracking resource mnemonic across a large project becomes a nightmare (and very very boring code typing for developers which usually impacts quality control).  Another pain with a large site is consistency of presentation.

 

What if I claim that all you need to do is toss the code below into a page and be done with coding!

 

The Web Page Content:

   1: <telerik:RadGrid runat="server" ID="AccountSummaryGrid" DataSourceID="AccountSummaryDb" AccessKey="X">
   2:     <MasterTableView AutoGenerateColumns="false" DataKeyNames="AccountName">
   3:         <Columns>
   4:             <telerik:GridBoundColumn DataField="AccountName" UniqueName="Grid_AccountName">
   5:             </telerik:GridBoundColumn>
   6:             <telerik:GridBoundColumn DataField="Description" UniqueName="Grid_AccountDescription">
   7:             </telerik:GridBoundColumn>
   8:             <telerik:GridBoundColumn DataField="Balance" UniqueName="Grid_AccountBalance">
   9:             </telerik:GridBoundColumn>
  10:             <telerik:GridBoundColumn DataField="CreditLimit" UniqueName="Grid_AccountCreditLimit">
  11:             </telerik:GridBoundColumn>
  12:             <telerik:GridBoundColumn DataField="OwnershipType" UniqueName="Grid_OwnershipType">
  13:             </telerik:GridBoundColumn>
  14:         </Columns>
  15:     </MasterTableView>
  16: </telerik:RadGrid>

With the page behind code being a horrible:

   1: protected void Page_Load(object sender, EventArgs e)
   2: { 
   3:     RadGridUtilities.ApplyDefaultSettings(AccountSummaryGrid);
   4: }

There are many tricks (and enhancement not shown), but the first item is to give the user the option to put the site into Accessibility Mode. If you give that option then only the pages while in Accessibility Mode must comply with Section 508. You can be as feature rich as you want elsewhere!!

 

This is what the one C# statement above does.

  • Provide web site defaults to the grid (every grid…), you want the defaults changed – it occurs in one spot only not in 100 pages!
  • Provide translation that is based off of the Control.Id (SO no more “Button1” but descriptive “ButtonToRetrieveStatement”
  • Modify the grid for what you want to do for accessibility.

There are a few items that I excluded (like automatically creating Resx entries for every phrase dynamically and self-auditing for 508 compliance) so the code is clearer.

/// <summary>
/// Applies the default settings to the page. If user customization is implemented
/// the settings here would come from their preferences stored in a Session object.
/// </summary>
/// <param name="grid">a radGrid control</param>
/// <param name="onGetOnly">Determines if the settings are down on every postback or only on first GET</param>
public static void ApplyDefaultSettings(RadGrid grid, bool onGetOnly)
{
    // Uniquenames should have an underscore (_) in it. grid_ is the recommended prefix so that
    //localization may identify items used in grids
    char[] sepUnique = { '_', ' ' };

    // Items requiring     
    grid.ItemCreated += grid_ItemCreatedAddRowScope;

    // Get translations. For items that Telerik may have translated use fallback version. 
    grid.MasterTableView.Caption = ResourceTranslation.TranslateField(string.Format(CultureInfo.CurrentCulture, "%ContentPage%{0}_Caption%", grid.ID));
    grid.MasterTableView.CommandItemSettings.AddNewRecordText = ResourceTranslation.TranslateField("%MasterPage%Grid_AddNewRecordText%", grid.MasterTableView.CommandItemSettings.AddNewRecordText);
    grid.MasterTableView.CommandItemSettings.ExportToCsvText = ResourceTranslation.TranslateField("%MasterPage%Grid_ExportToCsvText%", grid.MasterTableView.CommandItemSettings.ExportToCsvText);
    grid.MasterTableView.CommandItemSettings.ExportToExcelText = ResourceTranslation.TranslateField("%MasterPage%Grid_ExportToExcelText%", grid.MasterTableView.CommandItemSettings.ExportToExcelText);
    grid.MasterTableView.CommandItemSettings.ExportToPdfText = ResourceTranslation.TranslateField("%MasterPage%Grid_ExportToPdfText%", grid.MasterTableView.CommandItemSettings.ExportToPdfText);
    grid.MasterTableView.CommandItemSettings.ExportToWordText = ResourceTranslation.TranslateField("%MasterPage%Grid_ExportToWordText%", grid.MasterTableView.CommandItemSettings.ExportToWordText);
    grid.MasterTableView.CommandItemSettings.RefreshText = ResourceTranslation.TranslateField("%MasterPage%Grid_RefreshText%", grid.MasterTableView.CommandItemSettings.RefreshText);
    grid.MasterTableView.CssClass = ResourceTranslation.TranslateField("%MasterPage%Grid_CssClass%", grid.MasterTableView.CssClass);
    grid.MasterTableView.Summary = ResourceTranslation.TranslateField(string.Format(CultureInfo.CurrentCulture, "%ContentPage%{0}_Summary%", grid.ID));

    // This section would be used if images are to be customized for languages (unlikely)
    //    grid.MasterTableView.CommandItemSettings.AddNewRecordImageUrl = ResourceTranslation.TranslateField(grid.MasterTableView.CommandItemSettings.AddNewRecordImageUrl);
    //    grid.MasterTableView.CommandItemSettings.ExportToCsvImageUrl = ResourceTranslation.TranslateField(grid.MasterTableView.CommandItemSettings.ExportToCsvImageUrl);
    //    grid.MasterTableView.CommandItemSettings.ExportToExcelImageUrl = ResourceTranslation.TranslateField(grid.MasterTableView.CommandItemSettings.ExportToExcelImageUrl);
    //    grid.MasterTableView.CommandItemSettings.ExportToPdfImageUrl = ResourceTranslation.TranslateField(grid.MasterTableView.CommandItemSettings.ExportToPdfImageUrl);
    //    grid.MasterTableView.CommandItemSettings.ExportToWordImageUrl = ResourceTranslation.TranslateField(grid.MasterTableView.CommandItemSettings.ExportToWordImageUrl);
    
    // Site specific options. 
    // If User Options are allowed, the user's setting would be assigned instead.
    grid.AllowPaging = true;
    grid.AllowSorting = true;
    grid.ExportSettings.FileName = grid.ID;
    grid.ExportSettings.IgnorePaging = true;
    grid.ExportSettings.OpenInNewWindow = true;
    grid.ExportSettings.Pdf.Author = "Lassesen Consulting, LLC";
    grid.ExportSettings.Pdf.PageTitle = grid.MasterTableView.Caption;
    grid.ExportSettings.Pdf.Subject = grid.ID;
    grid.MasterTableView.AllowPaging = true;
    grid.MasterTableView.AllowSorting = true;
    grid.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.TopAndBottom;
    grid.MasterTableView.CommandItemSettings.ShowExportToCsvButton = true;
    grid.MasterTableView.CommandItemSettings.ShowExportToExcelButton = true;
    grid.MasterTableView.CommandItemSettings.ShowExportToPdfButton = true;
    grid.MasterTableView.CommandItemSettings.ShowExportToWordButton = true;
    grid.MasterTableView.PagerStyle.Mode = GridPagerMode.NextPrevNumericAndAdvanced;
    grid.PageSize = 60;

    // Changes for accessibility on a Grid Level
    // Remember hanidcap can be cognitive or physical -- so trim lots
    // of features
    if (Section508.UserSetting)
    {
        grid.AllowCustomPaging = false;
        grid.AllowFilteringByColumn = false;
        grid.AllowMultiRowEdit = false;
        grid.AllowMultiRowSelection = false;
        grid.MasterTableView.AllowPaging = false;
        grid.MasterTableView.AllowSorting = false;
        grid.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.None;
        grid.MasterTableView.CommandItemSettings.ShowExportToCsvButton = false;
        grid.MasterTableView.CommandItemSettings.ShowExportToExcelButton = false;
        grid.MasterTableView.CommandItemSettings.ShowExportToPdfButton = false;
        grid.MasterTableView.CommandItemSettings.ShowExportToWordButton = false;
        grid.MasterTableView.ShowGroupFooter = false;
        grid.ShowGroupPanel = false;
        grid.ShowStatusBar = false;
    }

    int colNo = 0;
    foreach (GridColumn col in grid.MasterTableView.Columns)
    {
        // uniquekeys are assumed to be compounded with an underscore
        //separator. Only last part is used as HeaderAbbr
        var translationkey = col.UniqueName;
        var parts = col.UniqueName.Split(sepUnique, System.StringSplitOptions.RemoveEmptyEntries);
        col.HeaderAbbr = parts[parts.Length - 1];
        // CHANGES for Accessibilty at a Column Level
        if (Section508.UserSetting)
        {
            col.AutoPostBackOnFilter = false;
            col.Groupable = false;
            col.HeaderButtonType = GridHeaderButtonType.PushButton;
            col.Resizable = false;
        }
        string tooltipMnemonic = string.Empty;
        //Determine if sortable and adopt appropriate tooltip
        if (grid.AllowSorting)
        {            
            if (! string.IsNullOrEmpty(col.SortExpression))
            {
                tooltipMnemonic = "Sort";
            }
            tooltipMnemonic =string.Format(CultureInfo.CurrentCulture, "%ContentPage%{0}_{1}Tooltip%", translationkey,tooltipMnemonic);
            col.HeaderTooltip = ResourceTranslation.TranslateField(tooltipMnemonic);
        }
        col.HeaderText = ResourceTranslation.TranslateField(string.Format(CultureInfo.CurrentCulture, "%ContentPage%{0}%", translationkey));
    }
}

 

The first item of importance is the event handler that is added

grid.ItemCreated += grid_ItemCreatedAddRowScope;

 

Grids require at least one <td scope=”row”> for Section 508 which is not natively provided by Telerik, so we must add it while the item is being created. This is done with the code below. The columns are those that are in the DataKeyNames, which makes it almost happens by designed-accident.

   1: /// <summary>
   2: /// Routine to add scope="row" to the grid for 508 compliance. The items are those specified in
   3: /// DataKeyNames
   4: /// </summary>
   5: /// <param name="sender">a telerik radgrid control</param>
   6: /// <param name="e"></param>
   7: static void grid_ItemCreatedAddRowScope(object sender, GridItemEventArgs e)
   8: {
   9:     if (e.Item is GridDataItem)
  10:     {
  11:         GridDataItem dataItem = e.Item as GridDataItem;
  12:         foreach (string key in dataItem.OwnerTableView.DataKeyNames)
  13:         {
  14:             foreach (GridColumn col in dataItem.OwnerTableView.Columns)
  15:             {
  16:                 if (col.IsBoundToFieldName(key))
  17:                 {
  18:                     TableCell cell = dataItem[col.UniqueName];
  19:                     cell.Attributes["scope"] = "row";
  20:                 }
  21:             }
  22:         }
  23:     }
  24: }

 

The other item is the ResourceTranslation.TranslateField which is a widget between the code and the usual handling of resources. It allows me to identify if a resource is missing as well as do some fancy stuff like “lookup the term and if you do not find it, then use what Telerik provides”;

 

That’s it.


From one of my blogs, http://www.31a2ba2a-b718-11dc-8314-0800200c9a66.com/
Mark Galbreath
Top achievements
Rank 2
 answered on 24 Feb 2010
0 answers
185 views
I just got into LINQ and read the chapters on it in Pro C# 2008 and the .NET 3.5 Platform and Pro ASP.NET 3.5 in C# 2008 (both from Apress).  I have run into an obstacle that I hope is not insurmountable: can I use a data projection when building a DataTable from a DataSet to be used as a datasource for a RadGrid?  Andrew Troelsen (Pro C# 2008) states that I cannot, but I have found no corroboration through Google.

For example, given I have an in-memory DataSet, ds, returned from Oracle that I want to use as the primary datasource for all RadGrids in my application (in other words, each RadGrid will take a subset of data from ds).  How do I make the following work?

1    var results = from t in ds.Tables[ 0 ].AsEnumerable()  
2  
3        group t by t.Field<string>( "MDEP" ), t.field<string>( "MDEP_DESC" ) into g  
4             
5        orderby g.Field<string>( "MDEP" )  
6             
7        select new {     
8           MDEP = g.Field<string>( "MDEP" ),  
9           MDEP_DESC = g.Field<string>( "MDEP_DESC" ),  
10          OA = g.Field<string>( "OA" ),  
11          OA_DESC = g.Field<string>( "OA_DESC" ),  
12          FY06 = g.Field<Int32>( "FY06" ),  
13          FY07 = g.Field<Int32>( "FY07" ),  
14          FY08 = g.Field<Int32>( "FY08" ),  
15          FY09 = g.Field<Int32>( "FY09" )  
16        };  
17  
18
19    DataTable dt = new DataTable();
20    dt = results.CopyToDataTable();
18    radGrid1.DataSource = dt

The compiler freaks out on line #3, claiming there is no "GroupBy" function for AsEnumerable(), which is more or less what Troelsen says will happen in his book.  The thing is, I HAVE to have these fields grouped.

I suspect that line #1 results in a list of datarows, which cannot be individually grouped, but I don't know LINQ well enough yet.

Any ideas?

tia,
Mark
Mark Galbreath
Top achievements
Rank 2
 asked on 24 Feb 2010
3 answers
132 views


When somebody clicks the left right arrow on calendar to change month..only 1 month should be moved..i mean if the calendar shows february and march and user clicks left arrow, then it should show january and february..currently it will show december and January.............I have set the  properties .... 

 

MultiViewColumns="1"  MultiViewRows="2"  Height="150"  EnableMultiSelect="false"  ShowOtherMonthsDays="false"
            Please tell me how will i solve this problem.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Iana Tsolova
Telerik team
 answered on 24 Feb 2010
3 answers
165 views
In the documentation for the RadNumericTextBox, there is the following line:
RadNumericTextBox does not support maximum and minimum values with a greater magnitude than +/- 2^46. Setting the MaxValue property to more than 2^46 or the MinValue property to less than -2^46 can cause abnormalities in the RadNumericTextBox behavior.

I need to use it with a larger value than 2^46, what sort of "abnormalities" should I look out for?

Thanks!
Veli
Telerik team
 answered on 24 Feb 2010
1 answer
125 views
Hi..

I am tagging the text in my editor using xhtml as in the following:
<my:Comment 
    
class=comment 
    
commentValue="comment text for arrested">ARRESTED
</my:Comment> MAN FOUND IN DITCH 

I want to be able to show a different context menu if the user right clicks the word "Arrested" rather than the normal context menu that shows when they right click the words "MAN" or "FOUND" etc...

I began by trying to implement the example shown in this forum post
http://www.telerik.com/community/forums/aspnet-ajax/editor/changing-context-menu-programmatically-client-side.aspx

however, the editor doesn't seem to understand the Comment tag.  It worked when I followed the example and used an IMG, but I would like it to work for the custom tags that I am defining.

Is this possible?
Dobromir
Telerik team
 answered on 24 Feb 2010
10 answers
222 views

Hello,

I'm attemping to populate a RadListBox with data from a SQL Server database. I've never done this in a Sharepoint environment so I tried it first in a straight ASP.NET project that I created with Visual Studio 2008. I copied the code example provided in the documentation almost to the letter and it all worked perfectly. The same code will not work in the Sharepoint project.
 

I'm creating the solution with Visual Studio 2008 and Visual Studio Extensions for Windows Sharepoint Services (VSeWSS). I'm putting the code to retrieve the data and populate the RadListBox in a C# code-behind file.
 

At least one difference between the Sharepoint and ASP.NET programs is that I can run the ASP.NET code through the local development server to test it, something that I cannot do with Sharepoint (I must build and deploy it to the Sharepoint server when I want to test the code).

Based on this I thought the problem might lie in the web.config file. I tried adding the System.Data assembly as a safe control, but that didn't work. Unfortunately it seems that I cannot debug a Sharepoint app as I can any other Visual Studio project so I cannot even provide a descriptive error message, only a web page that won't load.

Any suggestions or ideas would be greatly appreciated.

Thank you

Dimitar Milushev
Telerik team
 answered on 24 Feb 2010
6 answers
138 views
Hi

I have a Multiview that contains a  RadCalendar and a RadToolTipManager that shows tooltips for each day. Inside each tooltip contains data about that specific date and a button that needs to redirect the user to another View of the same page.

But when I click the button nothing happens. When I close the RadToolTip and press some other day it redirects me to that other View.

Does this have to do with VIEWSTATE?? 

THnx a lot!!

Svetlina Anati
Telerik team
 answered on 24 Feb 2010
2 answers
165 views
Hi,

I have aspx page with RadAjaxManager, RadComboBox, and PlaceHolder. The RadComboBox is ajaxified so that on SelectedIndexChanged, I utilize the LoadControl function to load a UserControl and add it to the controls of PlaceHolder. The path to the UserControl is dynamic (from db), based on a user-selected value from the RadComboBox (therefore I use LoadControl in server-side).

Is it possible to ajaxify the UserControl so that postback triggered by button on the UserControl would update only the UserControl (or part of it)?

Thanks for any assistance!
eyal
eyal
Top achievements
Rank 1
 answered on 24 Feb 2010
2 answers
392 views
Hi,
I'm using a RADNumeric Textbox (Type=Currency) and want to display nothing (ie. an empty textbox rather than £0.00) when I initially populate the form and the value to be shown in the control is zero.

I've found I can achieve this by checking whether the value to be loaded into the control is zero and, if it is, setting the textbox 'value' property to null. Is this the best way to achieve what I'm after or is there a better solution using any of the control's 'NumberFormat' properties?

I'm using ASP.NET AJAX Q3/2009 release.

Ian
Top achievements
Rank 1
 answered on 24 Feb 2010
2 answers
79 views
Hello Telerik

I need to create a Heirarchial Grid for Self Referencing data. The levels of nesting can be more than one.

At the last level of nesting, the Grid should have InLine Editing feature. User can click on any of it's cells and edit it. He should be able to edit as many Cells as he want and finally save the changes in the Database.

I have to add all the controls required for above the task dynamically through the Code Behind. I should not statically define the control in .aspx

Please help.

Thanks in Advance.
Vishnu
Princy
Top achievements
Rank 2
 answered on 24 Feb 2010
Narrow your results
Selected tags
Tags
+? more
Top users last month
Simon
Top achievements
Rank 2
Iron
Iron
Bob
Top achievements
Rank 3
Iron
Iron
Veteran
Marco
Top achievements
Rank 4
Iron
Iron
Iron
Grant
Top achievements
Rank 3
Iron
Iron
Iron
Kao Hung
Top achievements
Rank 1
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Simon
Top achievements
Rank 2
Iron
Iron
Bob
Top achievements
Rank 3
Iron
Iron
Veteran
Marco
Top achievements
Rank 4
Iron
Iron
Iron
Grant
Top achievements
Rank 3
Iron
Iron
Iron
Kao Hung
Top achievements
Rank 1
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?