0

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

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

我如何构建网格:

@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>
4

2 回答 2

1

您可以使用 .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,这样您就不必担心需要创建和使用NamespaceManagerwith SelectNodes(...)

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

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

HTH。

于 2013-07-15T13:09:42.140 回答
0

要获取 webgrid 的行数-

 var grid = ISGetObject("WebGrid1");
 var getTotal = grid.TotalRows;
 var getChangesTotal = grid.RootTable.GetChangesCount();
 alert(getTotal + getChangesTotal);
于 2013-07-15T13:06:04.080 回答