asp。net怎么上传多个附件。。并且显示多个附件的名字 如题啊高手指点啊.最好有代码。。和添加的控件 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://demo.swfupload.org/v220/index.htm教程网上很多了 http://www.cnblogs.com/beniao/archive/2009/05/15/1457679.html 多文件上传有代码。 楼主帅哥:你先把一次上传一个文件做好然后在别的页面 使用 iframe 多调用几次 不就OK了还可以通过JS控制 产生几个iframe 多好 1<style type="text/css"> .file { font: 10pt; color: black; } </style><script language="javascript">function addFile() {var fileDiv = document.all['fileDiv'];var strHtml = '<span><input type="file"> <button onclick="removeFile(parentNode);">删除</button><br></span>';fileDiv.innerHTML += strHtml;}function removeFile(obj) {obj.removeNode(true);}</script><form enctype="multipart/form-data"><div id="fileDiv"></div><a href="javascript:void(addFile());" class="file">添加附件</a></form>2<style type="text/css"> .file { font: 10pt; color: black; } </style><script language="javascript">var i=0;function addFile() {i++;currRow=conditionTable.insertRow();cellc=currRow.insertCell();cellcContext= '<input type="file" NAME="File+"+i> <button onclick="removeFile();">去除</button><br>';cellc.innerHTML=cellcContext;}function findTD(o){if (o.nodeName=="TR"||o.nodeName=="TABLE") return;if(o.nodeName=="TD")return (o);elsereturn (o.parentElement);}function removeFile(){o = findTD(event.srcElement);alert(o.parentElement.rowIndex*1);conditionTable.deleteRow(o.parentElement.rowIndex*1);}function uploadFile(){}</script><form enctype="multipart/form-data"><a href="javascript:void(addFile());" class="file">添加附件</a> <a href="javascript:void(uploadFile());" class="file">上传附件</a><div id="fileDiv" style='height:150px;top:150px;left:0px;overflow-x:auto;overflow-y:auto ;border-style:outset;border-width:1pt;border-color: black;'><table id=conditionTable border=1 ></table></div></form>3<div id="files"><div><input type=button onclick="add();" value=Attacthment><script>var html="<input name=title type=file> <input type=button value=Delete onclick=\"remove(this)\">";function add(){var o=document.all["files"];var div=document.createElement("div");div.innerHTML=html;o.appendChild(div);div.childNodes[0].click();}function remove(obj){obj.parentElement.parentElement.removeChild(obj.parentElement);}</script>4<html> <head id="Head1" runat="server"> <title>无标题页 </title> <script type="text/javascript"> function MultiSelector(list_target, max) { // Where to write the list this.list_target = list_target; // How many elements? this.count = 0; // How many elements? this.id = 0; // Is there a maximum? if (max){this.max = max;}else{this.max = -1;} /** * Add a new file input element */ this.addElement = function(element) { // Make sure it's a file input element if (element.tagName == 'INPUT' && element.type == 'file') { // Element name -- what number am I? element.name = 'file_' + this.id++; // Add reference to this object element.multi_selector = this; // What to do when a file is selected element.onchange = function() { var inputs = document.getElementsByTagName("input"); var count = 0; for(var i=0;i <inputs.length;i++) { if (inputs[i].type == 'file') { if(this.value==inputs[i].value) { count++; } } } if(count>1) { alert("该文件已存在!"); //this.outerHTML=this.outerHTML; return false; } if(!this.value.IsPicture()) { alert("只能上传图片!"); //this.outerHTML=this.outerHTML; return false; } // New file input var new_element = document.createElement('input'); new_element.type = 'file'; new_element.size = 1; new_element.className = "addfile"; // Add new element this.parentNode.insertBefore(new_element, this); // Apply 'update' to element this.multi_selector.addElement(new_element); // Update list this.multi_selector.addListRow(this); // Hide this: we can't use display:none because Safari doesn't like it this.style.position = 'absolute'; this.style.left = '-1000px'; } // If we've reached maximum number, disable input element if (this.max != -1 && this.count >= this.max) { element.disabled = true; } // File element counter this.count++; // Most recent element this.current_element = element; } else { // This can only be applied to file input elements! alert('Error: not a file input element'); } } /** * Add a new row to the list of files */ this.addListRow = function(element) { // Row div var new_row = document.createElement('div'); new_row.className="divName"; // Delete button var new_row_button = document.createElement('input'); new_row_button.type = 'button'; new_row_button.value = '删除'; // References new_row.element = element; // Delete function new_row_button.onclick = function() { // Remove element from form this.parentNode.element.parentNode.removeChild(this.parentNode.element); // Remove this row from the list this.parentNode.parentNode.removeChild(this.parentNode); // Decrement counter this.parentNode.element.multi_selector.count--; // Re-enable input element (if it's disabled) this.parentNode.element.multi_selector.current_element.disabled = false; // Appease Safari // without it Safari wants to reload the browser window // which nixes your already queued uploads return false; } // Set row value var filename = element.value.substring(element.value.lastIndexOf("//")+1); new_row.innerHTML = filename; // Add button new_row.appendChild(new_row_button); // Add it to the list this.list_target.appendChild(new_row); } } String.prototype.IsPicture = function() { //判断是否是图片 - strFilter必须是小写列举 var strFilter=".jpeg|.gif|.jpg|.png|.bmp|.pic|" if(this.indexOf(".")>-1) { var p = this.lastIndexOf("."); var strPostfix=this.substring(p,this.length) + '|'; strPostfix = strPostfix.toLowerCase(); if(strFilter.indexOf(strPostfix)>-1) { return true; } } return false; } </script> <style type="text/css"> a.addfile { background-image: url(http://p.mail.163.com/js31style/lib/0703131650/163blue/f1.gif); background-repeat: no-repeat; background-position: -823px -17px; display: block; float: left; height: 25px; margin-top: -1px; position: relative; text-decoration: none; top: 0pt; width: 65px; overflow:hidden; } a.addfile:hover { background-position: -911px -17px; } input.addfile { cursor: pointer !important; height: 25px; left: -6px; filter: alpha(opacity=0); position: absolute; width: 0px; z-index: -1; } .divName { float:left; margin-left:5px; } </style> <base target="_self" /> </head> <body> <form id="form1" runat="server" enctype="multipart/form-data"> <div> <table width="100%" style="text-align: left;"> <tr> <th align="center"> 添加文件 </th> </tr> <tr> <td> <a href="#" class="addfile" id="al"> <input id="my_file_element" class="addfile" runat="server" type="file" name="file_1" size="1" title="点击选择附件" /> </a> <asp:Button ID="btn_Ok" Height="25px" runat="server" Text="确定" OnClick="btn_Ok_Click" /> <br /> <%--Files:--%> <!-- This is where the output will appear --> <div id="files_list" style="border: none;width: 100%;"> </div> <script type="text/javascript"> <!-- Create an instance of the multiSelector class, pass it the output target and the max number of files --> var multi_selector = new MultiSelector(document.getElementById('files_list'), 100); <!-- Pass in the file element --> multi_selector.addElement(document.getElementById('my_file_element')); </script> </td> </tr> </table> </div> </form> </body> </html> 如何动态添加SqlParameter 帮忙看下,或者给个思路,关于分类,在线等.谢谢 请问如何在asp.net中打开word模板并控制word域.开发过的朋友请给个提示 newsletter 无法枚举查询结果多次!!! 请教一下,怎么在自己的网页上面 添加一个高考成绩查询的功能?(急啊) 创建购物车表的问题 在线急:为什么不能运行.aspx文件?怎么配置IIS6支持ASP.NET? 多线程问题 哪里有好一点,稳定的asp.net支持的收费主页空间? excel数据导入sqlserver数据库中 再触摸屏上实现播放图片
多文件上传有代码。
<style type="text/css"> .file { font: 10pt; color: black; } </style>
<script language="javascript">
function addFile() {
var fileDiv = document.all['fileDiv'];
var strHtml = '<span><input type="file"> <button onclick="removeFile(parentNode);">删除</button><br></span>';
fileDiv.innerHTML += strHtml;
}function removeFile(obj) {
obj.removeNode(true);
}
</script>
<form enctype="multipart/form-data">
<div id="fileDiv"></div>
<a href="javascript:void(addFile());" class="file">添加附件</a>
</form>
2
<style type="text/css"> .file { font: 10pt; color: black; } </style>
<script language="javascript">
var i=0;
function addFile() {
i++;currRow=conditionTable.insertRow();
cellc=currRow.insertCell();
cellcContext= '<input type="file" NAME="File+"+i> <button onclick="removeFile();">去除</button><br>';
cellc.innerHTML=cellcContext;}
function findTD(o){
if (o.nodeName=="TR"||o.nodeName=="TABLE") return;
if(o.nodeName=="TD")
return (o);
else
return (o.parentElement);
}
function removeFile(){
o = findTD(event.srcElement);
alert(o.parentElement.rowIndex*1);
conditionTable.deleteRow(o.parentElement.rowIndex*1);
}
function uploadFile(){}
</script>
<form enctype="multipart/form-data">
<a href="javascript:void(addFile());" class="file">添加附件</a> <a href="javascript:void(uploadFile());" class="file">上传附件</a>
<div id="fileDiv" style='height:150px;top:150px;left:0px;overflow-x:auto;overflow-y:auto ;border-style:outset;border-width:1pt;border-color: black;'>
<table id=conditionTable border=1 >
</table>
</div></form>
3
<div id="files">
<div>
<input type=button onclick="add();" value=Attacthment>
<script>
var html="<input name=title type=file> <input type=button value=Delete onclick=\"remove(this)\">";
function add()
{
var o=document.all["files"];
var div=document.createElement("div");
div.innerHTML=html;
o.appendChild(div);
div.childNodes[0].click();
}
function remove(obj)
{
obj.parentElement.parentElement.removeChild(obj.parentElement);
}
</script>4
<html>
<head id="Head1" runat="server">
<title>无标题页 </title> <script type="text/javascript">
function MultiSelector(list_target, max)
{
// Where to write the list
this.list_target = list_target;
// How many elements?
this.count = 0;
// How many elements?
this.id = 0;
// Is there a maximum?
if (max){this.max = max;}else{this.max = -1;}
/**
* Add a new file input element
*/
this.addElement = function(element)
{
// Make sure it's a file input element
if (element.tagName == 'INPUT' && element.type == 'file')
{
// Element name -- what number am I?
element.name = 'file_' + this.id++;
// Add reference to this object
element.multi_selector = this;
// What to do when a file is selected
element.onchange = function()
{
var inputs = document.getElementsByTagName("input");
var count = 0;
for(var i=0;i <inputs.length;i++)
{
if (inputs[i].type == 'file')
{
if(this.value==inputs[i].value)
{
count++;
}
}
}
if(count>1)
{
alert("该文件已存在!");
//this.outerHTML=this.outerHTML;
return false;
}
if(!this.value.IsPicture())
{
alert("只能上传图片!");
//this.outerHTML=this.outerHTML;
return false;
} // New file input
var new_element = document.createElement('input');
new_element.type = 'file';
new_element.size = 1;
new_element.className = "addfile";
// Add new element
this.parentNode.insertBefore(new_element, this);
// Apply 'update' to element
this.multi_selector.addElement(new_element);
// Update list
this.multi_selector.addListRow(this);
// Hide this: we can't use display:none because Safari doesn't like it
this.style.position = 'absolute';
this.style.left = '-1000px';
}
// If we've reached maximum number, disable input element
if (this.max != -1 && this.count >= this.max)
{
element.disabled = true;
}
// File element counter
this.count++;
// Most recent element
this.current_element = element;
}
else
{
// This can only be applied to file input elements!
alert('Error: not a file input element');
}
}
/**
* Add a new row to the list of files
*/
this.addListRow = function(element)
{
// Row div
var new_row = document.createElement('div');
new_row.className="divName";
// Delete button
var new_row_button = document.createElement('input');
new_row_button.type = 'button';
new_row_button.value = '删除';
// References
new_row.element = element;
// Delete function
new_row_button.onclick = function()
{
// Remove element from form
this.parentNode.element.parentNode.removeChild(this.parentNode.element);
// Remove this row from the list
this.parentNode.parentNode.removeChild(this.parentNode);
// Decrement counter
this.parentNode.element.multi_selector.count--;
// Re-enable input element (if it's disabled)
this.parentNode.element.multi_selector.current_element.disabled = false;
// Appease Safari
// without it Safari wants to reload the browser window
// which nixes your already queued uploads
return false;
}
// Set row value
var filename = element.value.substring(element.value.lastIndexOf("//")+1);
new_row.innerHTML = filename;
// Add button
new_row.appendChild(new_row_button);
// Add it to the list
this.list_target.appendChild(new_row);
}
}
String.prototype.IsPicture = function()
{
//判断是否是图片 - strFilter必须是小写列举 var strFilter=".jpeg|.gif|.jpg|.png|.bmp|.pic|"
if(this.indexOf(".")>-1)
{
var p = this.lastIndexOf(".");
var strPostfix=this.substring(p,this.length) + '|';
strPostfix = strPostfix.toLowerCase();
if(strFilter.indexOf(strPostfix)>-1)
{
return true;
}
}
return false;
}
</script> <style type="text/css">
a.addfile
{
background-image: url(http://p.mail.163.com/js31style/lib/0703131650/163blue/f1.gif);
background-repeat: no-repeat;
background-position: -823px -17px;
display: block;
float: left;
height: 25px;
margin-top: -1px;
position: relative;
text-decoration: none;
top: 0pt;
width: 65px;
overflow:hidden;
}
a.addfile:hover
{
background-position: -911px -17px;
} input.addfile
{
cursor: pointer !important;
height: 25px;
left: -6px;
filter: alpha(opacity=0);
position: absolute;
width: 0px;
z-index: -1;
}
.divName
{
float:left;
margin-left:5px;
}
</style>
<base target="_self" />
</head>
<body>
<form id="form1" runat="server" enctype="multipart/form-data">
<div>
<table width="100%" style="text-align: left;">
<tr>
<th align="center">
添加文件
</th>
</tr>
<tr>
<td>
<a href="#" class="addfile" id="al">
<input id="my_file_element" class="addfile" runat="server" type="file" name="file_1" size="1" title="点击选择附件" />
</a>
<asp:Button ID="btn_Ok" Height="25px" runat="server" Text="确定" OnClick="btn_Ok_Click" />
<br />
<%--Files:--%>
<!-- This is where the output will appear -->
<div id="files_list" style="border: none;width: 100%;">
</div>
<script type="text/javascript">
<!-- Create an instance of the multiSelector class, pass it the output target and the max number of files -->
var multi_selector = new MultiSelector(document.getElementById('files_list'), 100);
<!-- Pass in the file element -->
multi_selector.addElement(document.getElementById('my_file_element'));
</script>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>