Setting localized tooltips in a sort enabled radgrid
Problem statements
1. End user needs tooltips - even on the grid headers. (Not sure of scenario where user will move mouse over the grid headers, but our end users demanded for it).
2. Telerik grid normally has no problem with showing grid headers, but when showing sortable columns, it display linkbuttons for clicking and does not display the tooltip.
3. Although there is a custom way to display tooltips, we want tooltips from resource file (localized) and also do not want to hard code any string in the source code. We also want these tips to be localized.
Following is what we did:
protected void GridViewAccountDetails_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
if (e.Item is GridHeaderItem)
{
GridColumnCollection gridColumnCollection = GridViewFindAudit.MasterTableView.Columns;
GridHeaderItem gridHeaderItem = e.Item as GridHeaderItem;
foreach (GridColumn column in gridColumnCollection)
{
string ColumnUniqName = column.UniqueName;
string ColumnTooltip = Resources.Resource.ResourceManager.GetString(ColumnUniqName + "ToolTip");
if (GridViewFindAudit.AllowSorting)
{
LinkButton linkButton = (LinkButton)gridHeaderItem[ColumnUniqName].Controls[0];
linkButton.ToolTip = ColumnTooltip;
}
else
{
gridHeaderItem[ColumnUniqName].ToolTip = ColumnTooltip;
}
}
}
}
As you can see above,
1. We trap databound event
2. We apply our logic only when e.Item is GridHeaderItem
3. We use the defined columnuniquename as a key to refer the localized text. As there might be lot of other fields in the resource file, we add a suffix - "ToolTip" so that it does not mess with actual strings which can be replaced anytime by a person. (to differentiate tooltip keys from other normal translation keys)
4. If it is a normal grid header then we directly set the tooltip, else we get the linkbutton and then set the tooltip for the linkbutton.
1. End user needs tooltips - even on the grid headers. (Not sure of scenario where user will move mouse over the grid headers, but our end users demanded for it).
2. Telerik grid normally has no problem with showing grid headers, but when showing sortable columns, it display linkbuttons for clicking and does not display the tooltip.
3. Although there is a custom way to display tooltips, we want tooltips from resource file (localized) and also do not want to hard code any string in the source code. We also want these tips to be localized.
Following is what we did:
protected void GridViewAccountDetails_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
if (e.Item is GridHeaderItem)
{
GridColumnCollection gridColumnCollection = GridViewFindAudit.MasterTableView.Columns;
GridHeaderItem gridHeaderItem = e.Item as GridHeaderItem;
foreach (GridColumn column in gridColumnCollection)
{
string ColumnUniqName = column.UniqueName;
string ColumnTooltip = Resources.Resource.ResourceManager.GetString(ColumnUniqName + "ToolTip");
if (GridViewFindAudit.AllowSorting)
{
LinkButton linkButton = (LinkButton)gridHeaderItem[ColumnUniqName].Controls[0];
linkButton.ToolTip = ColumnTooltip;
}
else
{
gridHeaderItem[ColumnUniqName].ToolTip = ColumnTooltip;
}
}
}
}
As you can see above,
1. We trap databound event
2. We apply our logic only when e.Item is GridHeaderItem
3. We use the defined columnuniquename as a key to refer the localized text. As there might be lot of other fields in the resource file, we add a suffix - "ToolTip" so that it does not mess with actual strings which can be replaced anytime by a person. (to differentiate tooltip keys from other normal translation keys)
4. If it is a normal grid header then we directly set the tooltip, else we get the linkbutton and then set the tooltip for the linkbutton.
Comments
Post a Comment