以下是我测试GridView的代码,很简单就用到两个控件:GridView、SqlDataSource,数据库是自己的,代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="UserID" HeaderText="UserID" InsertVisible="False" ReadOnly="True"
SortExpression="UserID" />
<asp:BoundField DataField="UserName" HeaderText="UserName" SortExpression="UserName" />
<asp:BoundField DataField="RealName" HeaderText="RealName" SortExpression="RealName" />
<asp:BoundField DataField="Age" HeaderText="Age" SortExpression="Age" />
<asp:CheckBoxField DataField="Sex" HeaderText="Sex" SortExpression="Sex" />
<asp:BoundField DataField="Mobile" HeaderText="Mobile" SortExpression="Mobile" />
<asp:BoundField DataField="Phone" HeaderText="Phone" SortExpression="Phone" />
<asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
</Columns>
</asp:GridView>
</div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:AspNetStudyConnectionString2 %>"
SelectCommand="SELECT * FROM [UserInfo]"></asp:SqlDataSource>
</form>
</body>
</html>
结果执行的时候,报错:Microsoft JScript 运行时错误: 'theForm.__EVENTTARGET' 为空或不是对象
在网上找了找:很简单,把Form ID改掉就好了~,我改为:<form id="frm" runat="server">
结果还是一样的报错:Microsoft JScript 运行时错误: 'theForm.__EVENTTARGET' 为空或不是对象
急啊!请高手指点一下!!
------解决方案--------------------------------------------------------
不是很明白,反正我分页都是用PageDataSource在后台分的
------解决方案--------------------------------------------------------
var theForm = document.forms['form1'];
if (!theForm) {
theForm = document.form1;
}
参考
参考