如何交换或更改列数据 [英] How to swap or change column data
问题描述
我将名为dasset的datset绑定到gridview的一列.其值如下-
1
2
3
4
0
0
0
我在gridview的文本框中显示这些值.
我将选择一个字段并确认我的价值.
如果我将3更改为1,则den 1应该更改为3,例如swapping或,
如果我将2更改为0,则den 3将为2,4将为3或类似的排序,
如果我将4更改为0,则不会更改,因为4是最大值
表示我必须维持订单...
我必须通过单击按钮来实现这一点,新订单将存储在数据库中.
我尝试了多种方式进行Dis操作,例如1st将所有字段值存储在数组中并使用交换功能,但感到困惑...
请提出
我该如何实施Dis ..
thnx
i bind a column of gridview with datset named as Position. which has values as follows-
1
2
3
4
0
0
0
i''m showing these values in textboxes in gridview..
i''ll select a field and eneter my value.
if i change 3 to 1, den 1 should change to 3 like swapping or,
if i change 2 to 0 den 3 will be 2 and 4 will be 3 or like ordering,
and if i change 4 to 0 den no change because 4 is largest value
means i have to maintain the order...
i have to implement this with a button click and new order will be stored n database.
i tried dis with many ways like 1st store all fields values in array and use swapping but got confused ...
please suggest
how do i implement dis..
thnx
推荐答案
数据绑定到什么?您将需要重新排序.如果是IList< T>在某种情况下,您可以只使用remove/add/insert方法执行交换,或者进行临时复制并重新分配所有索引(不过最好暂时禁用该绑定).如果是数据库,则难度更大,从逻辑上讲,数据库甚至没有固定的顺序.
同样,这是一种笨拙的方法,允许重新排序.拖动行标题可能更符合用户的期望.它还具有的优点是,任何拖放操作都是一次移动(也许有多个行,但仍然是直接的位置交换),而不是任意重新分配索引,因此您不必更新整个数据源.
What are you data binding to? You will need to reorder that. If it''s a IList<T> of some kind you can just use remove/add/insert methods to perform the swaps, or take a temporary copy and reassign all the indices (probably best to temporarily disable the binding for that though). If it''s a database it is harder, and logically a database doesn''t even have a fixed order.
Also, this is kind of a clunky way to allow reordering. Dragging the row headers around is probably more what the user would expect. It also has the advantage that any drag-drop operation is a single movement (perhaps of multiple rows but still a straight positional swap) not an arbitrary reassignment of indices, so you don''t have to update the whole data source.
这是一个解决方案
Here is a solution for it
<html>
<head>
<title></title>
<script >
function Disable(var1)
{
var1.disabled=true;
window.open("Second.htm");
}
var old;
function Oldval(txtid)
{
old=txtid.value;
}
function Swap(txtid) {
var bool = true;
for (i = 0; i < document.forms[0].elements.length; i++) {
if (document.forms[0].elements[i].type == "text") {
if (document.forms[0].elements[i].value == txtid.value) {
document.forms[0].elements[i].value = old;
bool = false;
break;
}
else if (document.forms[0].elements.length == i && bool == true) {
alert('in');
txtid.value = old;
}
}
}
}
</script>
</head>
<body >
<form id="form1" >
<input type="button" id="one" onclick="Disable(this)" />
<input type="text" id="one" onclick="Oldval(this)" value="1" onblur="Swap(this)" />
<input type="text" id="one" onclick="Oldval(this)" value="2" onblur="Swap(this)"/>
<input type="text" id="one" onclick="Oldval(this)" value="3" onblur="Swap(this)"/>
<input type="text" id="one" onclick="Oldval(this)" value="4" onblur="Swap(this)"/>
<input type="text" id="one" onclick="Oldval(this)" value="5" onblur="Swap(this)"/>
<input type="text" id="one" onclick="Oldval(this)" value="6" onblur="Swap(this)"/>
<input type="text" id="one" onclick="Oldval(this)" value="7" onblur="Swap(this)"/>
<input type="text" id="one" onclick="Oldval(this)" value="8" onblur="Swap(this)"/>
</form>
</body>
</html>
我已经写了模糊的代码,您可以说服自己使用
i have written the code on blur you can use as per your convince
//now get each column that we want
Column1 = ExcelObject.XCelGetDataObject("A1", "A" + ExcelObject.XCelGetLastRow());
Column2 = ExcelObject.XCelGetDataObject("B1", "B" + ExcelObject.XCelGetLastRow());
Column4 = ExcelObject.XCelGetDataObject("D1", "D" + ExcelObject.XCelGetLastRow());
//shuffle the columns, swap the first and second columns
ExcelObject.XCelInsertData("A1", "A" + ExcelObject.XCelGetLastRow(), Column2);
ExcelObject.XCelInsertData("B1", "B" + ExcelObject.XCelGetLastRow(), Column1);
ExcelObject.XCelSort();
//the entire excel table is now sorted, re-read the information back to each object
Column1 = ExcelObject.XCelGetDataObject("A1", "A" + ExcelObject.XCelGetLastRow());
Column2 = ExcelObject.XCelGetDataObject("B1", "B" + ExcelObject.XCelGetLastRow());
Column3 = ExcelObject.XCelGetDataObject("C1", "C" + ExcelObject.XCelGetLastRow());
Column4 = ExcelObject.XCelGetDataObject("C1", "C" + ExcelObject.XCelGetLastRow());
这篇关于如何交换或更改列数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!