How I can replace an existing html val with a value calculated later using html and/or css? -


i creating html pass rest method, such as:

stringbuilder builder = new stringbuilder(); builder.append("<div class=\"row\">"); builder.append("<div class=\"col-md-6\">"); builder.append("<div class=\"bottomleft\">"); // todo: replace hardcoded val ("$9,814.81") actual val builder.append("<h2 class=\"sectiontext\">forecasted spend - $9,814.81</h2>"); 

(the preliminary html has been added prior this). after add live data so:

builder.append("<table>"); builder.append("<tr>"); builder.append("<th>item code</th>"); builder.append("<th class=\"rightjustifytext\">last week's usage</th>"); builder.append("<th class=\"rightjustifytext\">this week's price</th>"); builder.append("<th class=\"rightjustifytext\">forecasted spend</th>"); builder.append("</tr>");  decimal forecastedspend; int lastweeksusage; int loopcount = 0; int totalusage = 0; decimal totalforecastedspend = 0.0m; foreach (datarow dr in dtviewpricematrixvarianceresults.rows) {     builder.append("<tr>");     builder.append(string.format("<td>{0}</td>", dr["itemcode"]));     lastweeksusage = proactwebreportsconstsandutils.randomnumber(1, 1000);     totalusage = totalusage + lastweeksusage;     builder.append(string.format("<td class=\"rightjustifytext\">{0}</td>", proactwebreportsconstsandutils.addthousandsseparator(lastweeksusage, false)));     builder.append(string.format("<td class=\"rightjustifytext\">{0}</td>", proactwebreportsconstsandutils.moneyformat(convert.todecimal(dr["price"]), true)));     decimal currentprice = convert.todecimal(dr["price"]);     forecastedspend = lastweeksusage * currentprice;     totalforecastedspend = totalforecastedspend + forecastedspend;     builder.append(string.format("<td class=\"rightjustifytext\">{0}</td>", proactwebreportsconstsandutils.moneyformat(convert.todecimal(forecastedspend), true)));     builder.append("</tr>");     loopcount++;     if (loopcount >= 9) break; } 

(i add total vals total row after this). @ end close elements , pass contents of stringbuilder:

builder.append("</table>"); builder.append("</div>"); builder.append("</div>"); return builder.tostring(); 

the problem don't know value of totalforecastedspend (which value need replace teh dummy "$9,814.81" with) until populate html table table rows.tabledata. loop first, , save values in generic list use in loop, i'm wondering/hoping if there way replace value real 1 when arrive @ it, using either html and/or css accomplish it. possible and, if so, how? or "go to" considered harmful?

the rest method is:

[route("{unit}/{begdate}/{enddate}")] public httpresponsemessage getquadrantdata(string unit, string begdate, string enddate) {     _unit = unit;     _begindate = begdate;     _enddate = enddate;     string beginninghtml = getbeginninghtml();     string top10itemspurchasedhtml = gettop10itemspurchasedhtml();     string pricingexceptionshtml = getpricingexceptionshtml();     string forecastedspendhtml = getforecastedspendhtml();     string deliveryperformancehtml = getdeliveryperformancehtml();     string endinghtml = getendinghtml();     string htmltodisplay = string.format("{0}{1}{2}{3}{4}{5}",         beginninghtml,         top10itemspurchasedhtml,         pricingexceptionshtml,         forecastedspendhtml,         deliveryperformancehtml,         endinghtml);      return new httpresponsemessage()     {         content = new stringcontent(             htmltodisplay,             encoding.utf8,             "text/html"         )     }; } 

the html-generating code @ top of post getforecastedspendhtml() helper method.

is there trick can replace "$9,814.81" value later assigned totalforecastedspend, or forced pursue other option?

note: attempts add javascript/jquery have failed (see here, if interested) don't know if javascript solution me here.

udpate

this doesn't answer question, idea work, loop through , make calculations , save vals generic list first, , use thereafter:

first, created class:

public class forecastedspend {     public string itemcode { get; set; }     public int lastweeksusage { get; set; }     public decimal price { get; set; }     public decimal forecastedspendcalcd { get; set; } } 

...then replaced code above this:

int loopcount = 0; int totalusage = 0; decimal totalforecastedspend = 0.0m; list<forecastedspend> fslist = new list<forecastedspend>(); foreach (datarow dr in dtviewpricematrixvarianceresults.rows) {     forecastedspend fs = new forecastedspend();     fs.itemcode = dr["itemcode"].tostring();     fs.lastweeksusage = proactwebreportsconstsandutils.randomnumber(1, 1000);     totalusage = totalusage + fs.lastweeksusage;     decimal currentprice = convert.todecimal(dr["price"]);     fs.price = currentprice;     fs.forecastedspendcalcd = fs.lastweeksusage * currentprice;     totalforecastedspend = totalforecastedspend + fs.forecastedspendcalcd;     loopcount++;     fslist.add(fs);     if (loopcount >= 9) break; }  //builder.append("<h2 class=\"sectiontext\">forecasted spend - $9,814.81</h2>"); builder.append(string.format("<h2 class=\"sectiontext\">forecasted spend - {0}</h2>", proactwebreportsconstsandutils.moneyformat(totalforecastedspend, true))); builder.append("<table>"); builder.append("<tr>"); builder.append("<th>item code</th>"); builder.append("<th class=\"rightjustifytext\">last week's usage</th>"); builder.append("<th class=\"rightjustifytext\">this week's price</th>"); builder.append("<th class=\"rightjustifytext\">forecasted spend</th>"); builder.append("</tr>");  foreach (forecastedspend fs in fslist) {     builder.append("<tr>");     builder.append(string.format("<td>{0}</td>", fs.itemcode));     builder.append(string.format("<td class=\"rightjustifytext\">{0}</td>", proactwebreportsconstsandutils.addthousandsseparator(fs.lastweeksusage, false)));     builder.append(string.format("<td class=\"rightjustifytext\">{0}</td>", proactwebreportsconstsandutils.moneyformat(convert.todecimal(fs.price), true)));     builder.append(string.format("<td class=\"rightjustifytext\">{0}</td>", proactwebreportsconstsandutils.moneyformat(convert.todecimal(fs.forecastedspendcalcd), true)));     builder.append("</tr>"); } 

it works dandy.

another -standard- way transform result after generating , before rendering browser producing xml result , let browser transform proper xsl stylesheet.

this technologhy has several advantages:

  • it puts format apart data, practice.
  • it reduces bandwidth, because xsl delivered once device (and after, gets cached locally).
  • the transformation done natively browser, in practice fast direct html rendering.
  • it helps maintainability: shall format changed, server endpoint program has not modified @ all; xsl stylesheet.

Comments