繁体   English   中英

算表中的tr? (WebGrid)

[英]Count the tr's in a table? (WebGrid)

我有一张桌子,我想检查它是否填充。

下面显示了如何构建网格以及其在运行时环境中的外观。 我将如何计算行数?

我如何构建网格:

@using System.Dynamic
@{
    var result = new List<dynamic>();
    //Model.TrackingNumber = Model.RequestNumber.ToString();

    foreach (var proprow in Model.DDS)
    {
        var row = (IDictionary<string, object>)new ExpandoObject();
        Dictionary<string, object> eachPropRow = (Dictionary<string, object>)proprow;


        var fileName = proprow["Township"] + ", " + proprow["Erf"] + ", " + proprow["Portion"] + ", " + proprow["Property_Type"] + ", " + proprow["Unit"] + " " + "V?, " + DateTime.Now.ToString("(yyyy-MM-dd (HH.mm))"); //+ DateTime.Now.ToString("(yyyy-MM-dd (HH.mm))")
        foreach (KeyValuePair<string, object> keyValuePair in eachPropRow)
        {
            System.Web.HtmlString linkID;
            if (keyValuePair.Key == "Prop_ID")
            {

                linkID = Html.ActionLink(keyValuePair.Value.ToString(), "Valuation", new { PropID = keyValuePair.Value, Token = Model.Token, fileName, RequestNumber = Model.RequestNumber, ClientName = Model.ClientName, ReasonForValuation = Model.ReasonForValuation, ContactPerson = Model.ContactPerson, ContactNumber = Model.ContactNumber, Relation = Model.Relation, AccountNumber = Model.AccountNumber, BondAmount = Model.BondAmount, PurchasePrice = Model.PurchasePrice}, new { @class = "DownloadLink" });
                row.Add(keyValuePair.Key, linkID);
            }
            else
            {
                row.Add(keyValuePair);
            }
        }
        result.Add(row);
    }


    var grid = new WebGrid(result,null,null,30,false,false);

    @*@grid.GetHtml(tableStyle: "grid", headerStyle: "head", alternatingRowStyle: "alt");*@

    @grid.GetHtml(
       tableStyle: "grid",
       headerStyle: "grid-header",
       alternatingRowStyle: "grid-alternating-row", //grid-alternating-row
       selectedRowStyle: "grid-selected-row",
       rowStyle: "grid-row-style"

       )

  }

下面,我列出了运行时控制台中显示的表格:

<table class="grid">
    <thead>
        <tr class="grid-header"><th scope="col">Prop_ID</th>
            <th scope="col">Erf</th>
            <th scope="col">Street</th>
            <th scope="col">Unit</th>
            <th scope="col">Portion</th>
            <th scope="col">Size</th>
            <th scope="col">Suburb</th>
            <th scope="col">Township</th>
            <th scope="col">Province</th>
            <th scope="col">Property_Type</th>
            <th scope="col">Owner</th>
            <th scope="col">Title_Deed_No</th>
            <th scope="col">Purch_Price</th>
            <th scope="col">Purch_Date</th>
        </tr>
    </thead>
    <tbody>
        <tr class="grid-row-style">
            <td><a class="DownloadLink" href="/ReturnProperties/Valuation?PropID=14351160&amp;Token=f7a9d22c-ce87-45df-a8b1-a05bdba9e068&amp;fileName=HIGHVELD%20EXT%207%2C%201402%2C%200%2C%20FH%2C%20%20V%3F%2C%20(2013-07-15%20(14.53))&amp;RequestNumber=45735864378386V1">14351160</a></td>
            <td>1402</td>
            <td>77 SANTA MONICA</td>
            <td></td>
            <td>0</td>
            <td>750</td>
            <td>CENTURION GOLF ESTATE</td>
            <td>HIGHVELD EXT 7</td>
            <td>GA</td>
            <td>FH</td>
            <td>MOSSOP MAUREEN</td>
            <td>T101413/2007</td>
            <td>4800000</td>
            <td>20070611</td>
        </tr>
        <tr class="grid-alternating-row">
            <td><a class="DownloadLink" href="/ReturnProperties/Valuation?PropID=14351160&amp;Token=f7a9d22c-ce87-45df-a8b1-a05bdba9e068&amp;fileName=HIGHVELD%20EXT%207%2C%201402%2C%200%2C%20FH%2C%20%20V%3F%2C%20(2013-07-15%20(14.53))&amp;RequestNumber=45735864378386V1">14351160</a></td>
            <td>1402</td>
            <td>77 SANTA MONICA</td>
            <td></td>
            <td>0</td>
            <td>750</td>
            <td>CENTURION GOLF ESTATE</td>
            <td>HIGHVELD EXT 7</td>
            <td>GA</td>
            <td>FH</td>
            <td>MOSSOP IAN PAUL</td>
            <td>T101413/2007</td>
            <td>4800000</td>
            <td>20070611</td>
        </tr>
    </tbody>
    </table>

您可以使用.NET XML库和XPath来确定。 或使用免费的XPath测试工具,然后将XML复制粘贴到其中,并使用以下XPath表达式:

//table[@class='grid']//tr

使用.NET 1.x API,您可以实例化一个新的XML文档并按如下所示执行XPath:

XmlDocument tableDoc = new XmlDocument();
tableDoc.LoadXml( /* A string containing the HTML here -- but it better be well-formed */);
var trCount = tableDoc.SelectNodes("//table[@class='grid']//tr").Cast<XmlNode>().Count();

如果您使用的是XHTML,则应使用下面的XPath,这样就不必担心需要使用SelectNodes(...)创建和使用NamespaceManager

//*[local-name()='table' and @class='grid']//*[local-name()='tr']

还有更新的.NET API LINQ-to-XML。 我对它还不太熟悉,无法给您一个很好的例子。

HTH。

要获取webgrid的行数-

 var grid = ISGetObject("WebGrid1");
 var getTotal = grid.TotalRows;
 var getChangesTotal = grid.RootTable.GetChangesCount();
 alert(getTotal + getChangesTotal);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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