javascript获取gridview值失败!
我要用javascript获取girdview内的值,报错:0x800a138f - JavaScript 运行时错误: 无法获取未定义或 null 引用的属性“rows”
代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ChooseCustomerPage.aspx.cs" Inherits="ChooseCustomerPage" %>
<%@ Register Assembly="MyControls" Namespace="MyControls" TagPrefix="cc1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<script type="text/javascript">
function save() {
var table = document.getElementById(<%=GridView1.ClientID %>);
var rowindex = 0;
for(var i=1;i<table.rows.length;i++)
{
var input = table.rows[i].cells[0].getElementsByTagName("input")[0].checked;
if (input == true)
{
rowIndex = i;
return rowindex;
}
}
}
function closeShow() {
window.close();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:Label ID="Label1" runat="server" Text="选择客户:"></asp:Label>
<cc1:MyGridView ID="GridView1" runat="server" AllowPaging="True"
AutoGenerateColumns="False" CellPadding="4"
ForeColor="#333333"
OnPageIndexChanging="GridView1_PageIndexChanging"
PageSize="8"
hoverBackColor=""
hoverTextColor="">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField HeaderText="选择">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<input onclick="select" id="Checkbox1" type="checkbox" />
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" Width="50px" />
</asp:TemplateField>
<asp:BoundField DataField="customerID" HeaderText="ID">
<ItemStyle Width="50px" />
</asp:BoundField>
<asp:BoundField DataField="name" HeaderText="客户名" >
<ItemStyle Width="300px" />
</asp:BoundField>
<asp:BoundField DataField="phone" HeaderText="电话" >
<HeaderStyle Width="100px" />
</asp:BoundField>
<asp:BoundField DataField="address" HeaderText="详细地址" >
<HeaderStyle Width="150px" />
<ItemStyle Width="150px" />
</asp:BoundField>
<asp:BoundField DataField="EstablishName" HeaderText="创建人" >
<ItemStyle Width="80px" />
</asp:BoundField>
<asp:BoundField DataField="email" HeaderText="邮箱" >
<HeaderStyle Width="150px" />
<ItemStyle Width="200px" />
</asp:BoundField>
<asp:BoundField DataField="AsignName" HeaderText="负责人" >
<ItemStyle Width="80px" />
</asp:BoundField>
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
</cc1:MyGridView>
</form>
<p>
<input id="btnSave" type="button" value="保存退出" onclick="save()" /><input id="btnCancel"
type="button" value="退出" onclick="closeShow()" /></p>
</body>
</html>