aspx部分:
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="~/Models.asmx" />
</Services>
</asp:ScriptManager>
<div>
<div>
<br />
<div>
<asp:GridView ID="Gridview1" clientID="Gridview1" runat="server"></asp:GridView>
<br />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</div>
<input id="Button2" type="button" value="Get Model" onclick="getModelByID()" /><br />
</div>
</div>
</form>
JavaScript部分:
<script type="text/javascript" language="javascript">
function getModelByID() {
_4_layer.Models.GetAllModelss(SuccesCallBack);
}
function parseJSON(data) {
return window.JSON && window.JSON.parse ? window.JSON.parse(data) : (new Function("return " + data))();
}
function SuccesCallBack(result) {
obj = parseJSON(result);
var i = document.getElementById("TextBox1");
var j = document.getElementById("GridView1");
j.DataSource = obj;
j.Bind();
}
也可以使用
("<%= Gridview1.ClientID %>")
一切都没问题但是j在两个实现中都返回了null对象。 这是WebApp。在一开始,Gridview1为空,因此它不显示,并且没有html对象为它创建使用Dom对象。我能做什么 ?没有Jquery!
答案 0 :(得分:0)
var j = document.getElementById("Gridview1");
j.DataSource = obj;
&#13;
您似乎正在尝试使用不存在的方法和属性。
javascript中有bind()但是写了#34; bind&#34;它用于功能。 如果以前没有定义,则没有DataSource。
顺便问一下你为什么要用两个分号?
为了调试,可能会将代码拆分为:
答案 1 :(得分:0)
我通过手动输入行在page_load初始化Gridview1来解决问题,现在如何在不初始化网格的情况下执行此操作?