gridview无法正常工作 [英] gridview is not working

查看:66
本文介绍了gridview无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

萨拉姆2全部;
我有2个网格,当我选择n将gv1的记录移至gv2选定的行时,bt的问题是,当我想将另一个选定的行从gv1移至gv2时,先前移动的记录被删除了,因此出现了新的选定行.
我正在使用javascript.
我的代码如下
var gridview = document.getElementById(<%= gvPracticeFacility.ClientID%>");
var gridview1 = document.getElementById(<%= gvPracticesAssignedFacilities.ClientID%>");
var tr = document.createElement("tr");
var cell1 = document.createElement("td");
var celln = document.createElement("td");
var cell2 = document.createElement("td");
var cell3 = document.createElement("td");
var cell4 = document.createElement("td");
var cell5 = document.createElement("td");
var cell6 = document.createElement("td");
var cell7 = document.createElement("td");

var i = parseInt(document.getElementById(<%= hdnfldSelectedRow.ClientID%>").value);

cell1.innerHTML = gridview.rows [i] .childNodes [0] .innerHTML;
cell2.innerHTML = gridview.rows [i] .childNodes [1] .innerHTML;
cell3.innerHTML = gridview.rows [i] .childNodes [2] .innerHTML;
cell4.innerHTML = gridview.rows [i] .childNodes [3] .innerHTML;
cell5.innerHTML = gridview.rows [i] .childNodes [4] .innerHTML;
cell6.innerHTML = gridview.rows [i] .childNodes [5] .innerHTML;
cell7.innerHTML = gridview.rows [i] .childNodes [6] .innerHTML;
tr.appendChild(cell1);
tr.appendChild(cell2);
tr.appendChild(cell3);
tr.appendChild(cell4);
tr.appendChild(cell5);
tr.appendChild(cell6);
tr.appendChild(cell7);
gridview1.firstChild.appendChild(tr);

请告诉我我哪里错了.........!
提前感谢...!

sallam 2 all;
i hav 2 grids when i select n move gv1''s record to gv2 selected row is moved, bt the problem is that when i want to move another selectedrow from gv1 to gv2 the previous moved record is removed n new selected row is appeared.
i''m working in javascript.
My code is as follows
var gridview=document.getElementById("<%= gvPracticeFacility.ClientID %>");
var gridview1=document.getElementById("<%= gvPracticesAssignedFacilities.ClientID %>");
var tr = document.createElement("tr");
var cell1 = document.createElement("td");
var celln = document.createElement("td");
var cell2 = document.createElement("td");
var cell3 = document.createElement("td");
var cell4 = document.createElement("td");
var cell5 = document.createElement("td");
var cell6 = document.createElement("td");
var cell7 = document.createElement("td");

var i =parseInt(document.getElementById("<%= hdnfldSelectedRow.ClientID %>").value);

cell1.innerHTML = gridview.rows[i].childNodes[0].innerHTML;
cell2.innerHTML = gridview.rows[i].childNodes[1].innerHTML;
cell3.innerHTML = gridview.rows[i].childNodes[2].innerHTML;
cell4.innerHTML = gridview.rows[i].childNodes[3].innerHTML;
cell5.innerHTML = gridview.rows[i].childNodes[4].innerHTML;
cell6.innerHTML = gridview.rows[i].childNodes[5].innerHTML;
cell7.innerHTML = gridview.rows[i].childNodes[6].innerHTML;
tr.appendChild(cell1);
tr.appendChild(cell2);
tr.appendChild(cell3);
tr.appendChild(cell4);
tr.appendChild(cell5);
tr.appendChild(cell6);
tr.appendChild(cell7);
gridview1.firstChild.appendChild(tr);

plz tell me where i''m wrong.......!
Thanx in Advance......!

推荐答案

问题是在运行JavaScript之前发生的回发.
看看会发生什么,发生回发,然后将数据重新加载到数据网格中,在浏览器中显示页面,然后运行Javascript,这是第一次.
第二次,发生回发并将数据重新加载到datagrid中(将它们重置为原始数据),在浏览器中显示页面,然后您的javascript运行,这将为您提供正在发生的一切.
更改HTML不会更改后面代码中使用的数据,您需要做的是更改用于回发时填充数据网格的数据.

因此,我想做的是在第一页加载时获取数据并将其存储在会话变量中,然后在回发时获取会话变量中的数据,对其进行修改并将其设置为您的数据网格的数据,不要打扰使用javascript.
The problem is the postback that occurs BEFORE your javascript runs.

Look at what happens, postback occurs and the data is reloaded into the datagrids, page displays in the browser then your javascript runs, that''s the first time.
Second time, postback occurs and the data is reloaded into the datagrids (reseting them back to original), page displays in the browser then your javascript runs, which will give you what you are seeing happen.
Changing the HTML does not change the data that is used in the code behind, what you need to do is change the data that is used to populate the datagrids on postback.

So what I would look at doing is on first page load get the data and store it in session variables, then on postback get the data out of the session variables modify it and set it as the data for your datagrids, don''t bother with the javascript.


代码似乎很好,但我认为问题出在

gridview1.firstChild.appendChild(tr);

检查firstChild元素,究竟显示了什么.

或另一种情况是,可能是您的页面在移动行时将被刷新(回发).
The code seems to be fine, but I think the problem is at the line

gridview1.firstChild.appendChild(tr);

Check the firstChild element, what exactly it shows.

or another scenario is , may be your page will be refreshed(postback) at the time of moving row.


这篇关于gridview无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆