Permalink
Browse files

added innerhtml to Link

  • Loading branch information...
1 parent d323644 commit e5e3e8577b25e0f338757753c37d6a73358dcb08 @shashankshetty shashankshetty committed Feb 4, 2014
@@ -13,6 +13,7 @@
using System.Web.UI.WebControls;
using FluentWebControls.Controls;
+using FluentWebControls.Extensions;
namespace FluentWebControls
{
@@ -32,6 +33,7 @@ public interface ICommandColumn
string CssClass { get; }
string HeaderCssClass { get; }
string ImageUrl { get; }
+ string InnerHtml { get; }
string Text { get; }
}
@@ -50,6 +52,7 @@ public CommandColumn(Func<T, string, Control> getControl)
internal string CssClass { private get; set; }
internal string HeaderCssClass { private get; set; }
internal string ImageUrl { private get; set; }
+ internal string InnerHtml { private get; set; }
internal string Text { private get; set; }
string ICommandColumn.HeaderCssClass
@@ -67,6 +70,11 @@ string ICommandColumn.ImageUrl
get { return ImageUrl; }
}
+ string ICommandColumn.InnerHtml
+ {
+ get { return InnerHtml; }
+ }
+
string ICommandColumn.Alt
{
get { return Alt; }
@@ -84,7 +92,19 @@ string ICommandColumn.CssClass
public void Render(T item, int rowIndex, HtmlTextWriter writer)
{
- var control = _getControl(item, Text ?? String.Format("<img src='{0}' alt='{1}'/>", ImageUrl, Alt));
+ var columnText = Text.ToNonNull().EscapeForHtml();
+
+ if (InnerHtml != null)
+ {
+ columnText = InnerHtml;
+ }
+ else if (ImageUrl != null && Alt != null)
+ {
+ columnText = String.Format("<img src='{0}' alt='{1}'/>", ImageUrl, Alt);
+ }
+
+ var control = _getControl(item, columnText);
+
var cell = new TableCell
{
HorizontalAlign = Align.ToHorizontalAlign(),
@@ -60,6 +60,7 @@ public CommandItem(Func<T, string, string> getControl)
internal string Alt { private get; set; }
internal string CssClass { private get; set; }
internal string ImageUrl { private get; set; }
+ internal string InnerHtml { private get; set; }
internal string Text { private get; set; }
internal bool WrapWithSpan { private get; set; }
@@ -125,7 +126,7 @@ private LinkData GetLink(T item)
{
var navigateUrl = _getLink(item);
var linkId = String.Format("lnk{0}", navigateUrl.Replace('/', '_').TrimStart(new[] { '_' }));
- return new LinkData().WithId(linkId).WithUrl(navigateUrl).WithLinkText(Text).WithLinkImageUrl(ImageUrl, Alt);
+ return new LinkData().WithId(linkId).WithUrl(navigateUrl).WithLinkText(Text).WithInnerHtml(InnerHtml).WithLinkImageUrl(ImageUrl, Alt);
}
}
}
@@ -48,6 +48,12 @@ public static CommandColumn<T> WithImage<T>(this CommandColumn<T> commandColumn,
return commandColumn;
}
+ public static CommandColumn<T> WithInnerHtml<T>(this CommandColumn<T> commandColumn, string innerHtml)
+ {
+ commandColumn.InnerHtml = innerHtml;
+ return commandColumn;
+ }
+
public static CommandColumn<T> WithText<T>(this CommandColumn<T> commandColumn, string text)
{
commandColumn.Text = text;
@@ -42,6 +42,12 @@ public static CommandItem<T> WithImage<T>(this CommandItem<T> commandItem, strin
return commandItem;
}
+ public static CommandItem<T> WithInnerHtml<T>(this CommandItem<T> commandItem, string innerHtml)
+ {
+ commandItem.InnerHtml = innerHtml;
+ return commandItem;
+ }
+
public static CommandItem<T> WithText<T>(this CommandItem<T> commandItem, string text)
{
commandItem.Text = text;
@@ -60,6 +60,12 @@ public static LinkData WithLinkImageUrl(this LinkData linkData, string imageUrl,
return linkData;
}
+ public static LinkData WithInnerHtml(this LinkData linkData, string innerHtml)
+ {
+ linkData.InnerHtml = innerHtml;
+ return linkData;
+ }
+
public static LinkData WithLinkText(this LinkData linkData, string linkText)
{
linkData.LinkText = linkText;
@@ -27,6 +27,7 @@ public interface ILinkData
string Id { get; }
string IdWithPrefix { get; }
string ImageUrl { get; }
+ string InnerHtml { get; }
string LinkText { get; }
string MouseOverText { get; }
string Rel { get; }
@@ -141,6 +142,10 @@ public override string ToString()
{
sb.Append("<img src='" + ImageUrl + "' alt='" + Alt + "'/>");
}
+ else if (InnerHtml != null)
+ {
+ sb.Append(InnerHtml);
+ }
else
{
sb.Append(LinkText.EscapeForHtml());
@@ -187,6 +192,11 @@ string ILinkData.ImageUrl
{
get { return ImageUrl; }
}
+ internal string InnerHtml { private get; set; }
+ string ILinkData.InnerHtml
+ {
+ get { return InnerHtml; }
+ }
internal string LinkText { private get; set; }
string ILinkData.LinkText
{

0 comments on commit e5e3e85

Please sign in to comment.