如何使用数据绑定控件实现不换页提交数据?
时间:2010-05-16 15:17:00
如何使用数据绑定控件实现不换页提交数据?
Chunfeng.html
' 提交页面
< html>
< head>
< title> 本页提交 - aspxhome.com< /title>
< /head>
< !--DataSource is Data Binding control-->
< object classid="clsid:333C7BC4-460F-11D0-BC04-0080C7055A83" id="DataSource" VIEWASTEXT>
< param NAME="UseHeader" VALUE="True">
< param NAME="FieldDelim" VALUE=",">
< param NAME="DataURL" VALUE="ProcessData.asp?ID=0">
< /object>
< script for=DataSource event=ondatasetcomplete>
Name.value = "";
Age.value = "";
Age.disabled = true;
outputButton.disabled = true;
< /script>
< script>
var rowindex = 0;
function clickTR()
{
var srcElement = event.srcElement;
while(srcElement.tagName != "TR")
{
srcElement = srcElement.parentElement;
}
rowindex = srcElement.rowIndex;
Name.value = srcElement.cells(0).innerText;
Age.value = srcElement.cells(1).innerText;
Age.disabled = false;
outputButton.disabled = false;
}
function submitData()
{
var rs = DataSource.recordset;
rs.AbsolutePosition = rowindex;
if(rs("Name").value == Name.value && rs("Age").value == Age.value)
{
alert("Data no change"); return;
}
var szReturn;
szReturn = "ProcessData.asp?Name=" + Name.value + "&ID=" + rs("ID").value + "&Age=" + Age.value;
DataSource.DataURL = szReturn;
DataSource.reset();
outputButton.disabled = true;
}
< /script>
< body>
< table datasrc=#DataSource CELLPADDING="0" CELLSPACING="0" BORDER="1" WIDTH="100%">
< thead>
< th>姓名< /th>
< th>年龄< /th>
< /thead>
< tr style="Cursor:Hand" onclick="clickTR();" onmouseover="this.style.backgroundColor='silver';"
onmouseout="this.style.backgroundColor='white';">
< td><span datafld=Name>< /td>
< td><span datafld=Age>< /td>
< /tr>
< /table>
< hr>
< table width=100%>
< tr>
< td width=30%>姓名</td>
< td width=30%>年龄</td>
< td width=100%> </td>
< /tr>
< tr>
< td width=30%>< input style="width:100%" id=Name disabled>< /td>
< td width=30%>< input style="width:100%" id=Age disabled>< /td>
< td width=100%>< input type=button value="现在提交" id= outputButton disabled on click="submitData( );">< /td>
< /tr>
< /table>
< /body>
< /html>
ProcessData.asp
' 数据处理
< %@ Language=VBScript %>
< %
dim id
dim enter
enter = chr(10)
id = request.querystring("ID")
set d = server.createobject("scripting.filesystemobject")
if id < > 0 then
set read = d.opentextfile("c:\inetpub\wwwroot\test\Data.csv ")
set write = d.Createtextfile("c:\inetpub\wwwroot\test\ Data1.csv ")
dim index
dim string
id = id + 1
index = 1
while not read.AtEndOfStream
if index = id then
dim name
dim age
name = request.querystring("name")
age = request.querystring("age")
string = id - 1 & "," & name & "," & age
write.WriteLine(string)
read.ReadLine
else
write.writeLine(read.ReadLine)
end if
index = index + 1
wend
read.Close
write.Close
d.CopyFile "c:\inetpub\wwwroot\test\Data1.csv",
"c:\inetpub\wwwroot\test\ Data.csv "
d.DeleteFile "c:\inetpub\wwwroot\test\ Data1.csv "
end if
set file = d.opentextfile("c:\inetpub\wwwroot\test\ Data.csv ")
while not file.AtEndOfStream
Response.write (file.ReadLine)
Response.write enter wend file.Close %>
Data.csv
' 数据文件
ID:int,Name:string,Age:int
1,Victor, 23
2,Bill,31
3,kenny,31
4,hunter,24