Alternative to .Net for manually creating / TR / TD tables?

I have a bunch of code here that looks like this:

if (stateTax > 0)
{
    tr = new TableRow();
    tbl.Rows.Add(tr);
    td = new TableCell();
    td.CssClass = "stdLabel";
    td.Text = "NY State Tax";
    tr.Cells.Add(td);

    td = new TableCell();
    td.Text = string.Format("{0:C}", stateTax);
    td.CssClass = "justRight";
    tr.Cells.Add(td);
}

This is a terrible hash of data and layout, but every time something like this happens, a special class or control is created.

What I usually do is write a helper function that is concise but ugly:

if (stateTax > 0)
    MakeRow(tbl, "NY State Tax", "stdLabel", 
                 string.Format("{0:C}", stateTax), "justRight");

And now I think: haven't I done this 100 times before? Isn't there a more modern way?

Just to be explicit: this is a whole list of different labels and values. They do not come from any particular data source, and the rules for suppressing rows are different. This example has only two columns, but I have other places with a lot.

, : , GridView.

Repeater ShoppingCart, . , , : , , , , , . , , - .

- , , ; .

, a Control, Visible = false, , . , .

+3
4

GridView ASP.NET.

+6

GridView.

. JavaScript Ajax .

0

, ...

  • , .

  • Literal , , . , , . text... "hello world", , html, , , "hello world".

-1
source

Source: https://habr.com/ru/post/1748427/


All Articles