)>}]
شركة التطبيقات المتكاملة لتصميم وبرمجة البرمجيات الخاصة ش.ش.و.
Integrated Applications Programming Company
Home » Code Library » HtmlHelper (Ia.Cl.Models)

Public general use code classes and xml files that we've compiled and used over the years:

HtmlHelper for ASP.Net Core.

    1: using System;
    2: using System.IO;
    3: using Microsoft.AspNetCore.Html;
    4: using Microsoft.AspNetCore.Mvc.Razor;
    5: using Microsoft.AspNetCore.Mvc.Rendering;
    6: using Microsoft.AspNetCore.Mvc.ViewFeatures;
    7: using Microsoft.Extensions.Configuration;
    8:  
    9: namespace Ia.Cl.Models
   10: {
   11:     ////////////////////////////////////////////////////////////////////////////
   12:  
   13:     /// <summary publish="true">
   14:     /// HtmlHelper for ASP.Net Core.
   15:     /// </summary>
   16:     /// <remarks> 
   17:     /// Copyright © 2023-2024 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
   18:     ///
   19:     /// This library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
   20:     /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
   21:     ///
   22:     /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
   23:     /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
   24:     /// 
   25:     /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
   26:     /// 
   27:     /// Copyright notice: This notice may not be removed or altered from any source distribution.
   28:     /// </remarks> 
   29:     public static class HtmlHelper
   30:     {
   31:         /*
   32: _ViewImports.cshtml (second line is the important change):
   33: 
   34: @using Ia.Cl.Models.HtmlHelper
   35: @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
   36: 
   37: *.cshtml:
   38: 
   39: <div>@Html.GridView()</div>         
   40:         */
   41:  
   42:         private static IConfigurationRoot _configuration;
   43:  
   44:         ////////////////////////////////////////////////////////////////////////////
   45:  
   46:         /// <summary>
   47:         ///
   48:         /// </summary>
   49:         public static IHtmlContent GridView(this IHtmlHelper htmlHelper)
   50:         {
   51:             return new HtmlString("<strong>GridView</strong>");
   52:  
   53:             /*
   54: <asp:GridView AutoGenerateColumns="false" ShowFooter="false" CssClass="gridview" EmptyDataText="<span class=gv>There are no data records to display.</span>" GridLines="Horizontal" _BackColor="White" BorderWidth="0px" BorderStyle="None" BorderColor="#E7E7FF" CellPadding="5" CellSpacing="1" runat="server">
   55: <RowStyle BackColor="WhiteSmoke" HorizontalAlign="Center"/>
   56: <AlternatingRowStyle BackColor="White" HorizontalAlign="Center"/>
   57: <SelectedRowStyle ForeColor="Red" BackColor="#B5C7DE" HorizontalAlign="Center"/>
   58: <EditRowStyle BackColor="WhiteSmoke" />
   59: <HeaderStyle ForeColor="White" BackColor="#aaaadd" HorizontalAlign="Center" />
   60: <FooterStyle ForeColor="#4A3C8C" BackColor="#B5C7DE" HorizontalAlign="Center" />
   61: <PagerSettings Mode="Numeric" Position="Bottom" PageButtonCount="10"/>
   62: <PagerStyle ForeColor="White" BackColor="#aaaadd" VerticalAlign="Middle" HorizontalAlign="Left"/>
   63: </asp:GridView>
   64: 
   65: <asp:DetailsView AutoGenerateRows="false" EmptyDataText="<span class=dv>There are no data records to display.</span>" GridLines="Horizontal" BackColor="White" BorderWidth="1px" BorderStyle="Solid" BorderColor="Teal" CellPadding="3" CellSpacing="1" runat="server">
   66: <RowStyle ForeColor="#4A3C8C" BackColor="White" HorizontalAlign="Center"/>
   67: <AlternatingRowStyle BackColor="MintCream" HorizontalAlign="Center"/>
   68: <EditRowStyle BackColor="WhiteSmoke" />
   69: <HeaderStyle ForeColor="White" BackColor="#aaaadd" HorizontalAlign="Center" Wrap="false"/>
   70: <FooterStyle ForeColor="White" BackColor="#aaaadd" HorizontalAlign="Center" Wrap="false"/>
   71: <PagerSettings Mode="Numeric" Position="Bottom" PageButtonCount="10"/>
   72: <PagerStyle ForeColor="White" BackColor="#aaaadd" VerticalAlign="Middle" HorizontalAlign="Left"/>
   73: </asp:DetailsView>
   74: 
   75: <asp:DataList RepeatDirection="Horizontal" ItemStyle-VerticalAlign="Top" AlternativeItemStyle-VerticalAlign="Top" runat="server"/>
   76: 
   77: <asp:Calendar ShowGridLines="true" DayNameFormat="FirstTwoLetters" TitleStyle-ForeColor="White" TitleStyle-BackColor="#aaaadd" DayHeaderStyle-ForeColor="White" DayHeaderStyle-BackColor="#ccccff" NextMonthText="»" NextPrevStyle-ForeColor="White" NextPrevStyle-Font-Size="XLarge" NextPrevStyle-Font-Bold="true" PrevMonthText="«" OtherMonthDayStyle-ForeColor="#ddddff" WeekendDayStyle-BackColor="#ffffff" FirstDayOfWeek="Sunday" runat="server">
   78: <SelectedDayStyle ForeColor="White" BackColor="Tomato" />
   79: </asp:Calendar>
   80: 
   81: @* ================================== *@
   82: 
   83: @*
   84: <asp:GridView SkinId="list_gv" AutoGenerateColumns="false" ShowFooter="true" CssClass="gridview" EmptyDataText="<span class=gv>There are no data records to display.</span>" GridLines="Horizontal" BackColor="White" BorderWidth="0px" BorderStyle="None" BorderColor="#E7E7FF" CellPadding="5" CellSpacing="1" runat="server">
   85: <RowStyle ForeColor="#4A3C8C" BackColor="White" HorizontalAlign="Center" Wrap="false"/>
   86: <AlternatingRowStyle ForeColor="#4A3C8C" BackColor="White" HorizontalAlign="Center" Wrap="false"/>
   87: <SelectedRowStyle ForeColor="Red" BackColor="#B5C7DE" HorizontalAlign="Center" Wrap="false"/>
   88: <EditRowStyle BackColor="WhiteSmoke" />
   89: <HeaderStyle ForeColor="White" BackColor="#aaaadd" HorizontalAlign="Center" Wrap="false"/>
   90: <FooterStyle ForeColor="#4A3C8C" BackColor="#B5C7DE" HorizontalAlign="Center" Wrap="false"/>
   91: <PagerSettings Mode="Numeric" Position="TopAndBottom" PageButtonCount="10"/>
   92: <PagerStyle ForeColor="White" BackColor="#aaaadd" VerticalAlign="Middle" HorizontalAlign="Left"/>
   93: </asp:GridView>
   94: 
   95: <asp:GridView SkinId="light_gv" AutoGenerateColumns="false" ShowFooter="false" CssClass="gridview" EmptyDataText="<span class=gv3>There are no data records to display.</span>" GridLines="Horizontal" BackColor="#e0e0e0" BorderWidth="0px" BorderStyle="None" BorderColor="#e0e0e0" CellPadding="5" CellSpacing="1" AllowSorting="false" AllowPaging="false" runat="server">
   96: <RowStyle ForeColor="#4A3C8C" BackColor="MintCream" HorizontalAlign="Center" Wrap="false"/>
   97: <AlternatingRowStyle BackColor="MintCream" HorizontalAlign="Center" Wrap="false"/>
   98: <SelectedRowStyle ForeColor="#4A3C8C" BackColor="MintCream" HorizontalAlign="Center" Wrap="false"/>
   99: <EditRowStyle BackColor="WhiteSmoke" />
  100: <HeaderStyle ForeColor="White" BackColor="#B5C7DE" HorizontalAlign="Center" Wrap="false"/>
  101: <FooterStyle ForeColor="White" BackColor="#B5C7DE" HorizontalAlign="Center" Wrap="false"/>
  102: <PagerSettings Mode="Numeric" Position="Bottom" PageButtonCount="10"/>
  103: <PagerStyle ForeColor="White" BackColor="#aaaadd" VerticalAlign="Middle" HorizontalAlign="Left"/>
  104: </asp:GridView>
  105: 
  106: <asp:GridView SkinId="classic_gv" AutoGenerateColumns="false" ShowFooter="false" CssClass="gridview" EmptyDataText="<span class=gv>There are no data records to display.</span>" BackColor="WhiteSmoke" BorderWidth="0px" BorderStyle="None" BorderColor="#E7E7FF" CellPadding="5" CellSpacing="1" GridLines="Horizontal" runat="server">
  107: <RowStyle BackColor="White" HorizontalAlign="Center" Wrap="false"/>
  108: <AlternatingRowStyle BackColor="#EFF3FB" HorizontalAlign="Center" Wrap="false"/>
  109: <SelectedRowStyle ForeColor="333333" BackColor="#D1DDF1" Font-Bold="True" HorizontalAlign="Center" Wrap="false"/>
  110: <EditRowStyle BackColor="WhiteSmoke" />
  111: <HeaderStyle ForeColor="White" BackColor="#507CD1" Font-Bold="True" HorizontalAlign="Center" Wrap="false"/>
  112: <FooterStyle BackColor="#507CD1" ForeColor="White" HorizontalAlign="Center" Wrap="false"/>
  113: <PagerSettings Mode="Numeric" Position="Bottom" PageButtonCount="10"/>
  114: <PagerStyle ForeColor="White" BackColor="#2461BF" VerticalAlign="Middle" HorizontalAlign="Left"/>
  115: </asp:GridView>
  116: 
  117: <asp:GridView SkinId="simple_gv" AutoGenerateColumns="false" CssClass="gridview" EmptyDataText="<span class=gv>There are no data records to display.</span>" GridLines="Horizontal" BackColor="White" BorderWidth="0px" BorderStyle="None" BorderColor="Wheat" CellPadding="5" CellSpacing="1" runat="server">
  118: <RowStyle ForeColor="#4A3C8C" BackColor="White" HorizontalAlign="Center" Wrap="false"/>
  119: <AlternatingRowStyle ForeColor="#4A3C8C" BackColor="White" HorizontalAlign="Center" Wrap="false"/>
  120: <SelectedRowStyle ForeColor="Red" BackColor="#B5C7DE" HorizontalAlign="Center" Wrap="false"/>
  121: <EditRowStyle BackColor="WhiteSmoke" />
  122: <HeaderStyle ForeColor="White" BackColor="LightSlateGray" HorizontalAlign="Center" Wrap="false"/>
  123: <PagerSettings Mode="Numeric" Position="TopAndBottom" PageButtonCount="10"/>
  124: <PagerStyle ForeColor="White" BackColor="#aaaadd" VerticalAlign="Middle" HorizontalAlign="Left"/>
  125: </asp:GridView>
  126: 
  127: <asp:GridView SkinId="paper_gv" AutoGenerateColumns="false" ShowFooter="true" CssClass="gridview" EmptyDataText="<span class=gv>There are no data records to display.</span>" GridLines="Horizontal" BackColor="White" BorderWidth="0px" BorderStyle="None" BorderColor="#E7E7FF" CellPadding="4" CellSpacing="1" runat="server">
  128: <RowStyle ForeColor="#4A3C8C" BackColor="White" HorizontalAlign="Center"/>
  129: <AlternatingRowStyle ForeColor="#4A3C8C" BackColor="White" HorizontalAlign="Center"/>
  130: <SelectedRowStyle ForeColor="Red" BackColor="#B5C7DE" HorizontalAlign="Center"/>
  131: <EditRowStyle BackColor="WhiteSmoke" />
  132: <HeaderStyle ForeColor="#4A3C8C" BackColor="WhiteSmoke" HorizontalAlign="Center" Wrap="false"/>
  133: <FooterStyle ForeColor="#4A3C8C" BackColor="WhiteSmoke" HorizontalAlign="Center" Wrap="false"/>
  134: <PagerSettings Mode="Numeric" Position="TopAndBottom" PageButtonCount="10"/>
  135: <PagerStyle ForeColor="White" BackColor="#aaaadd" VerticalAlign="Middle" HorizontalAlign="Left"/>
  136: </asp:GridView>
  137: 
  138: 
  139: 
  140: <asp:GridView CssClass="gridview" CellPadding="3" BorderColor="LightGray" Font-Size="9pt" runat="server">
  141: <HeaderStyle ForeColor="WhiteSmoke" BackColor="#563C5C" Font-Bold="false" HorizontalAlign="Center" />
  142: <SelectedRowStyle ForeColor="Red" BackColor="#B5C7DE" HorizontalAlign="Center"/>
  143: <RowStyle CssClass="row-style" />
  144: <AlternatingRowStyle CssClass="alternating-row-style" />
  145: </asp:GridView>
  146: 
  147: <asp:RadioButtonList RepeatDirection="Horizontal" runat="server"/>
  148: 
  149: 
  150: 
  151:              */
  152:         }
  153:  
  154:         ////////////////////////////////////////////////////////////////////////////
  155:  
  156:         /// <summary>
  157:         ///
  158:         /// </summary>
  159:         public static IHtmlContent HelloWorld(this IHtmlHelper html, string name)
  160:         {
  161:             var span = new TagBuilder("span");
  162:             span.InnerHtml.Append("Hello, " + name + "!");
  163:  
  164:             var br = new TagBuilder("br") { TagRenderMode = TagRenderMode.SelfClosing };
  165:  
  166:             string result;
  167:  
  168:             using (var writer = new StringWriter())
  169:             {
  170:                 span.WriteTo(writer, System.Text.Encodings.Web.HtmlEncoder.Default);
  171:                 br.WriteTo(writer, System.Text.Encodings.Web.HtmlEncoder.Default);
  172:                 result = writer.ToString();
  173:             }
  174:  
  175:             return new HtmlString(result);
  176:         }
  177:  
  178:         ////////////////////////////////////////////////////////////////////////////
  179:  
  180:         /// <summary>
  181:         ///
  182:         /// </summary>
  183:         public static IHtmlContent SubmitButton(this IHtmlHelper htmlHelper, string value, string name)
  184:         {
  185:             string str = "<input type='submit' value ='" + value + "'name='" + name + "' />";
  186:             return new HtmlString(str);
  187:         }
  188:  
  189:         ////////////////////////////////////////////////////////////////////////////
  190:         ////////////////////////////////////////////////////////////////////////////
  191:     }
  192:  
  193:     ////////////////////////////////////////////////////////////////////////////
  194:     ////////////////////////////////////////////////////////////////////////////
  195: }