简体   繁体   中英

HTML to ASP.net web form page

i have this page ASP.Net Web Forms Page

<!-- Sidebar menu -->               
    <div id="sidebar-menu ">

    <div id="topPanel"
    <asp:Table runat="server" ID="table_PageHeader">
        <asp:TableHeaderRow>
            <asp:TableHeaderCell>
                <asp:HyperLink ID="hyperlink_TruckList" runat="server" Text="Truck List" NavigateUrl="~/View/Trucklist.aspx" Font-Underline="false"></asp:HyperLink>
            </asp:TableHeaderCell>
            <asp:TableHeaderCell>
                <asp:HyperLink ID="hyperlink_Reports" runat="server" Text="Reports" NavigateUrl="~/View/Reports.aspx" Font-Underline="false"></asp:HyperLink>
            </asp:TableHeaderCell>
            <asp:TableHeaderCell>
                <asp:HyperLink ID="hyperlink_Profile" runat="server" Text="Profile" NavigateUrl="~/View/Profile.aspx" Font-Underline="false"></asp:HyperLink>
            </asp:TableHeaderCell>
        </asp:TableHeaderRow>
    </asp:Table>
</div>

want to implement this

<!-- Sidebar menu -->               
                <div id="sidebar-menu">
                    <ul>
                        <li><a href="index.html" style="font-size: 18px; color: black"><i class="glyphicon glyphicon-info-sign" style="color:black"></i> Truck Data </a></li>
                        <li><a href="#fakelink" style="font-size: 18px; color: black"><i class="glyphicon glyphicon-folder-close" style="color:black"></i> Maintenance Record </a></li>
                        <li><a href="#fakelink" style="font-size: 18px; color: black"><i class="glyphicon glyphicon-calendar" style="color:black"></i> Maintenance Schedule </a></li>
                    </ul>
                </div><!-- End div #sidebar-menu -->
        </div><!-- End div .body .rows .scroll-y -->
    </div>
    <!-- END SIDEBAR -->

How can i insert the <li> and <i> in the Asp.net Web Form? Thanks in advance

At you interacting with the elements server side? If not just add the HTML as is. ASPX pages work fine with HTML elements.

If you want to interact with the elements server side, give them an ID and add runat="server" . Eg:

<div id="sidebar-menu" runat="server">

You can then access server side with sidebar-menu .

I believe you want to populate the unordered list from code behind. One option would be to make use of HtmlGenericControl class.

Your list item mark up looks like this

<li><a href="index.html" style="font-size: 18px; color: black"><i class="glyphicon glyphicon-info-sign" style="color:black"></i> Truck Data </a></li>

I believe the text should be within the <i></i> tags. So it should look like this.

<li><a href="index.html" style="font-size: 18px; color: black"><i class="glyphicon glyphicon-info-sign" style="color:black">Truck Data</i></a></li>

Based on this you can just have a placeholder in the aspx page and set it from code behind. Here in the example I am just populating a list item. Based on your needs you can loop/ create additional list items.

place holder in aspx

<asp:PlaceHolder ID="sidemenu" runat="server" />

code behind

HtmlGenericControl list = new HtmlGenericControl("ul");

HtmlGenericControl li = new HtmlGenericControl("li");

HyperLink a = new HyperLink();
a.NavigateUrl = "index.html";
a.Attributes.Add("style", "font-size: 18px; color: black");

HtmlGenericControl i = new HtmlGenericControl("i");
i.Attributes.Add("class", "glyphicon glyphicon-info-sign");
i.Attributes.Add("style", "color:black");
i.InnerText = "Truck Data";

a.Controls.Add(i);

li.Controls.Add(a);
list.Controls.Add(li);

sidemenu.Controls.Add(list);

namespace

using System.Web.UI.HtmlControls;

Generated markup

<ul>
<li>
    <a href="index.html" style="font-size: 18px; color: black">
        <i class="glyphicon glyphicon-info-sign" style="color:black">Truck Data</i>
    </a>
<li>
</ul>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM