简体   繁体   中英

Display the output of a function in a <div> in c#.net

The below code is in Web Form aspx.cs file and needs to be displayed in front end. So how to loop inside div tags?

foreach (DataRowView row in dv)
{
    Response.Write(row["Content"].ToString());
    Response.Write("&nbsp&nbsp");
    Response.Write(row["Page"].ToString());
    Response.Write("<br/>");             
}

I was going to say something similar to NateBarbettini, but his answer is simpler. So you should do this:

In your .aspx file have your div declared like this:

<div id="div1" runat="server"></div>

And in your .cs code behind, in your Page_Load event, do this:

StringBuilder sb = new StringBuilder();
foreach (DataRowView row in dv)             
    sb.Append(row["Content"].ToString() + "&nbsp&nbsp" + row["Page"].ToString() + "<br/>");
div1.InnerHtml = sb.ToString();

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