Not exactly a new control but in our company we have started creating extension methods for configuring your controls to do things that we commonly use, so we dont have to keep duplicating code some of these things are basically taking your code examples and tweaking them slightly.
You could create (maybe as a seperate download) a library with extension methods in that do your examples for us, once such example from our code-base would be adding a tooltip to a grid row and passing in the key from the row.
This is our extension method for that...
public
static
void
Configure_TooltipifyGridRows(
this
RadGrid grid, RadToolTipManager tt,
string
ascxFile,
string
dataKeyName,
string
targetControlId)
{
tt.AjaxUpdate += (sender, e) =>
{
string
[] parts = e.Value.Split(
'|'
);
//Does it belong to this grid...
if
(grid.ClientID == parts[0])
{
Control ctrl = grid.Page.LoadControl(ascxFile);
e.UpdatePanel.ContentTemplateContainer.Controls.Add(ctrl);
IToolTipUserControl uc = ctrl
as
IToolTipUserControl;
if
(uc !=
null
)
{
uc.SetArguments(parts[1]);
}
}
};
grid.ItemDataBound +=(sender,e)=>
{
if
(e.Item.ItemType == GridItemType.Item || e.Item.ItemType == GridItemType.AlternatingItem)
{
Control target = String.IsNullOrEmpty(targetControlId) ?
e.Item : e.Item.FindControl(targetControlId);
if
(!Object.Equals(target,
null
))
{
if
(!Object.Equals(tt,
null
))
{
//Add the button (target) id to the tooltip manager
string
val = String.Format(
"{0}|{1}"
,grid.ClientID,(e.Item
as
GridDataItem).GetDataKeyValue(dataKeyName).ToString());
tt.TargetControls.Add(target.ClientID, val,
true
);
}
}
}
};
grid.ItemCommand += (sender, e) =>
{
if
(e.CommandName ==
"Sort"
|| e.CommandName ==
"Page"
)
{
var ctrls = tt.TargetControls.Cast<ToolTipTargetControl>().Where(c=>c.Value.StartsWith(String.Format(
"{0}|"
,grid.ClientID))).ToList();
ctrls.ForEach(c=>tt.TargetControls.Remove(c));
}
};
}