首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在一张表里数tr?(WebGrid)

在一张表里数tr?(WebGrid)
EN

Stack Overflow用户
提问于 2013-07-15 21:00:32
回答 2查看 455关注 0票数 0

我有一个表,我想检查它是否填充。

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

如何构建网格:

代码语言:javascript
运行
复制
@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"

       )

  }

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

代码语言:javascript
运行
复制
<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>
EN

回答 2

Stack Overflow用户

发布于 2013-07-15 21:09:42

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

代码语言:javascript
运行
复制
//table[@class='grid']//tr

使用XML1.xAPI,您可以实例化一个新的.NET文档并执行XPath,如下所示:

代码语言:javascript
运行
复制
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

代码语言:javascript
运行
复制
//*[local-name()='table' and @class='grid']//*[local-name()='tr']

还有较新的XML-to- .NET。我对它还不够熟悉,不能给你一个很好的例子。

HTH。

票数 1
EN

Stack Overflow用户

发布于 2013-07-15 21:06:04

要获取webgrid的行数-

代码语言:javascript
运行
复制
 var grid = ISGetObject("WebGrid1");
 var getTotal = grid.TotalRows;
 var getChangesTotal = grid.RootTable.GetChangesCount();
 alert(getTotal + getChangesTotal);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17654888

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档