怎么实现列表框的双击事件啊。我现在是想这样的:我有两个列表框,一个列表框已经显示了文件(例:显示“F:\恐龙园”里所有的文件)。双击一个选项后,这个选项就到另一个列表框里去了。并且在另一个列表框里显示的时候名字上增加了一些东西。
例:我双击一个名为“123.txt”的选项。在另一个列表框里显示为“123.txt 12312”。并且想把“123.txt”这个文件移到另一个文件夹(例“F:\常州”)下面是我列表框里显示文件的代码。另一个列表框的ID是 _ListBox确认文件
protected void Page_Load(object sender, EventArgs e)
{
//********显示文件***************************************
if (IsPostBack)//如果不是首次加载页面,而是回发提交
{
}
else
{
// Make a reference to a directory.
string[] filepath = Directory.GetFiles(@"F:\恐龙园");
// Get a reference to each directory in that directory.
FileInfo[] files = new FileInfo[filepath.Length];
for (int i = 0; i < filepath.Length; i++)
{
files[i] = new FileInfo(filepath[i]);
}
// Display the names of the directories.
foreach (FileInfo dri in files)
_ListBox文件列表.Items.Add(dri.Name);
}
}
例:我双击一个名为“123.txt”的选项。在另一个列表框里显示为“123.txt 12312”。并且想把“123.txt”这个文件移到另一个文件夹(例“F:\常州”)下面是我列表框里显示文件的代码。另一个列表框的ID是 _ListBox确认文件
protected void Page_Load(object sender, EventArgs e)
{
//********显示文件***************************************
if (IsPostBack)//如果不是首次加载页面,而是回发提交
{
}
else
{
// Make a reference to a directory.
string[] filepath = Directory.GetFiles(@"F:\恐龙园");
// Get a reference to each directory in that directory.
FileInfo[] files = new FileInfo[filepath.Length];
for (int i = 0; i < filepath.Length; i++)
{
files[i] = new FileInfo(filepath[i]);
}
// Display the names of the directories.
foreach (FileInfo dri in files)
_ListBox文件列表.Items.Add(dri.Name);
}
}
列表框的ID是:_ListBox文件列表。
<asp:ListItem Value="1">1</asp:ListItem>
<asp:ListItem Value="2">2</asp:ListItem>
<asp:ListItem Value="3">3</asp:ListItem>
<asp:ListItem Value="4">4</asp:ListItem>
<asp:ListItem Value="5">5</asp:ListItem>
</asp:ListBox>function submitForm()
{
document.forms[0].submit();
}protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{ }
else
{
ListItem item = ListBox1.SelectedItem;
string filePath = item.Text;
//对文件进行拷贝
}
}
列表框的双击函数能不能写下的
列表框的双击函数能不能写下的给列表框添加双击事件ondblclick="submitForm();"
submitForm
提前到后台的
只要加了这个函数,双击列表框选项后,就会调用
private void _ListBox文件列表_Dbclick()
{
//添加双击引发的事件的相应的处理代码
}
函数了?
这是个js函数的,当然放在前台的了
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default11.aspx.cs" Inherits="Default11" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
<script type="text/javascript">
function submitForm()
{
document.forms[0].submit();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ListBox ondblclick="submitForm();" ID="ListBox1" runat="server" Width="128px">
<asp:ListItem Value="1">1</asp:ListItem>
<asp:ListItem Value="2">2</asp:ListItem>
<asp:ListItem Value="3">3</asp:ListItem>
<asp:ListItem Value="4">4</asp:ListItem>
<asp:ListItem Value="5">5</asp:ListItem>
</asp:ListBox>
</div>
</form>
</body>
</html>
.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;public partial class Default11 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{ }
else
{
ListItem item = ListBox1.SelectedItem;
string filenamt = item.Text;
//copy file to dest dir
}
}
}
private void _ListBox文件列表_Dbclick()
{
//添加双击引发的事件的相应的处理代码
_DropDownList栏目.Items.Clear();
}
双击函数里的代码蛮~