尝试按顺序将逐行数据追加到变量中

时间:2018-11-21 06:43:16

标签: c# asp.net

在读取数据时,我要按以下提到的顺序先读取网格的第一行数据,然后将其追加到表中,然后读取第二行,然后追加.i表示读取的第一个值是1sizMin,2sizeMax,3tolMin,4tolMax rownum = 1然后是第二,第三,但不知道该怎么做。

+----------+----------+--------+--+
| prop_name | property | rownum |  |
+----------+----------+--------+--+
| 1NDia    |        1 |      1 |  |
| 1sizMin  |        1 |      1 |  |
| 3tolMin  |        3 |      1 |  |
| 4tolMax  |        4 |      1 |  |
| 2sizeMax |        2 |      1 |  |
| 1NDia    |        2 |      2 |  |
| 1sizMin  |        5 |      2 |  |
| 3tolMin  |        7 |      2 |  |
| 4tolMax  |        8 |      2 |  |
| 2sizeMax |        6 |      2 |  |
| 1NDia    |        3 |      3 |  |
| 1sizMin  |        9 |      3 |  |
| 3tolMin  |       11 |      3 |  |
| 4tolMax  |       12 |      3 |  |
| 2sizeMax |       10 |      3 |  |
+----------+----------+--------+--+

c#代码

var sizMinStringFrst = "";
var sizMinStringSnd = "";
var sizMinStringThrd = "";
var sizMinStringFr = "";
int StdSize = 0;
var lblStdSize_Tolerm =htmltable
while (ReadData.Read())
      {
        if (prop_name == "1sizMin")
                    {
                        sizMinStringFrst = tdc_property;
                        StdSize = StdSize+1;
                    }
                    if (prop_name == "2sizeMax")
                    {
                        sizMinStringSnd = tdc_property;
                        StdSize = StdSize + 1;
                    }
                    if (prop_name == "3tolMin")
                    {
                        sizMinStringThrd = tdc_property;
                        StdSize = StdSize + 1;
                    }
                    if (prop_name == "4tolMax")
                    {
                        sizMinStringFr = tdc_property;
                        StdSize = StdSize + 1;
                    }
                    if (StdSize % 4 == 0)
                    { 
                    var newTable = "<tr><td class='td-First-col-value'><center>" + sizMinStringFrst + "</center></td>" +
                    "<td class='td-First-col-value'><center>" + sizMinStringSnd + "</center></td>" +
                    "<td class='td-First-col-value'><center>" + sizMinStringThrd + "</center></td>" +
                    "<td class='td-First-col-value'><center>" + sizMinStringFr + "</center></td></tr>";
                    lblStdSize_Tolerm = lblStdSize_Tolerm + newTable;

                }
}
lblStdSize_Toler.Text = lblStdSize_Tolerm+ "</table>";

我在顶部定义了四个变量来存储属性值 和StdSize变量作为计数器,并将其除以4,这样,当找到第一行列数据时,它将类似地追加到表中,但是逻辑有些错误。退出循环后,该表将绑定到标签,任何实现该想法的想法将不胜感激。

0 个答案:

没有答案