我在这是在注释中显示的代码得到错误(请仔细阅读)错误获取财产“行”在GridView
<script type="text/javascript" src="http://code.jquery.com/jquery- 2.2.1.min.js"></script>
<script type="text/javascript">
var grid = document.getElementById("<%=gvCustomers.ClientID%>");//gvCustomers is the ID of a gridview
val();
function val() {
if (grid.rows.length > 0) {//Unable to get property 'rows' of null or 'undefined' value
alert(grid.rows.length);
}
}
</script>
我要去哪里错了?即使我没有空的gridview!
的HTML代码也在这里:
<form id="form1" runat="server">
<div>
<asp:GridView ID="gvCustomers" runat="server" AutoGenerateColumns="false" ShowHeaderWhenEmpty ="true"
DataKeyNames="CustomerID" OnRowDataBound="OnRowDataBound">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID ="btn" Text ="+" runat="server" />
<asp:Panel ID="pnlOrders" runat="server" Style="display: none">
<asp:GridView ID="gvOrders" runat="server" AutoGenerateColumns="false" CssClass = "ChildGrid">
<Columns>
<asp:BoundField ItemStyle-Width="150px" DataField="OrderId" HeaderText="Order Id" />
<asp:BoundField ItemStyle-Width="150px" DataField="OrderDate" HeaderText="Date" />
</Columns>
</asp:GridView>
</asp:Panel>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField ItemStyle-Width="150px" DataField="ContactName" HeaderText="Contact Name" />
<asp:BoundField ItemStyle-Width="150px" DataField="City" HeaderText="City" />
</Columns>
</asp:GridView>
</div>
</form>
首先你初始化网格对象之前调用你的函数... – Alexis
哦,我知道了让我试试这个 –
你可以添加你的gridview的html代码吗? – Alexis