错哪了?在线!!!!

tiantian1980 2004-04-30 06:58:27
<% @ Page language="C#"%>
<script language="C#" runat="server">
public void ToRigtList(object sender,EventArgs e)
{
for(int i=0; i<lbox1.Items.Count;i++)
{
ListItem item=lbox1.Items[i];
if(item.Selected)
{
lbox2.Items.Add(item);
lbox1.Items.Remove(item);
}
}
}
public void ToLeftList(object sender,EventArgs e)
{
for(int i=0; i<lbox2.Items.Count;i++)
ListItem item=lbox2.Items[i];
if(item.Selected)
{
lbox1.Items.Add(item);
lbox2.Items.Remove(item);
}
}
</script>
<html>
<head>
<title><title>
</head>
<body>
<b>ListBox演示</b>
<hr>
<form runat="server">
<table>
<tr>
<td>
<b>ListBox容器1:</b><br>
<asp:ListBox id="lbox1" Rows=5 SelectionMode="Multiple" runat="server">
<asp:ListItem>天天</asp:ListItem>
<asp:ListItem>天健</asp:ListItem>
<asp:ListItem>皇帝</asp:ListItem>
<asp:ListItem>皇后</asp:ListItem>
<asp:ListItem>靖靖</asp:ListItem>
</asp:ListBox>
</td>
<td>
<asp:Button id="ToRight" Text="-->" OnClick="ToRightList" runat="server"/>
<asp:Button id="ToLeft" Text="<--" OnClick="ToLeftList" runat="server"/>
</td>
<td>
<b>ListBox容器2:</b><br>
<asp:ListBox id="lbox2" Rows=5 SelectionMode="Multiple" runat="server"/>
</td>
</form>
</body>
</html>


...全文
58 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
wangsaokui 2004-05-01
  • 打赏
  • 举报
回复
12点前给分我还可以在排行榜上涨涨!!谢谢!
wangsaokui 2004-05-01
  • 打赏
  • 举报
回复
晚了,兄弟!

前台就是你的页面,文件名后缀为aspx
后台就是你的代码,文件名后缀为aspx.vb或aspx.cs
tiantian1980 2004-05-01
  • 打赏
  • 举报
回复
哪位仁兄,解释下前台后台,不懂!
我一直就一下就运行出来!
回复人: wangsaokui(无间道II(前传)) 分一定给!就今12点前吧!
wangsaokui 2004-04-30
  • 打赏
  • 举报
回复
后台:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace WebApplication2
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.ListBox lbox1;
protected System.Web.UI.WebControls.Button ToRight;
protected System.Web.UI.WebControls.Button ToLeft;
protected System.Web.UI.WebControls.ListBox lbox2;

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.ToRight.Click += new System.EventHandler(this.ToRight_Click);
this.ToLeft.Click += new System.EventHandler(this.ToLeft_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void ToRight_Click(object sender, System.EventArgs e)
{
for(int i=0; i<lbox1.Items.Count;i++)
{
ListItem item=lbox1.Items[i];
if(item.Selected)
{
lbox2.Items.Add(item.Text);
lbox1.Items.Remove(item);
}
}
}

private void ToLeft_Click(object sender, System.EventArgs e)
{
for(int i=0; i<lbox2.Items.Count;i++)
{
ListItem item=lbox2.Items[i];
if(item.Selected)
{
lbox1.Items.Add(item.Text);
lbox2.Items.Remove(item);
}
}
}
}
}
wangsaokui 2004-04-30
  • 打赏
  • 举报
回复
前台:
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="WebApplication2.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title></title>
</HEAD>
<body>
<b>ListBox演示</b>
<hr>
<form runat="server" ID="Form1">
<table>
<tr>
<td>
<b>ListBox容器1:</b><br>
<asp:ListBox id="lbox1" Rows="5" SelectionMode="Multiple" runat="server">
<asp:ListItem>天天</asp:ListItem>
<asp:ListItem>天健</asp:ListItem>
<asp:ListItem>皇帝</asp:ListItem>
<asp:ListItem>皇后</asp:ListItem>
<asp:ListItem>靖靖</asp:ListItem>
</asp:ListBox>
</td>
<td>
<asp:Button id="ToRight" Text="-->" runat="server" /><BR>
<asp:Button id="ToLeft" Text="<--" runat="server" />
</td>
<td>
<b>ListBox容器2:</b><br>
<asp:ListBox id="lbox2" Rows="5" SelectionMode="Multiple" runat="server" />
</td>
</tr>
</table>
</form>
</body>
</HTML>
hnahzx 2004-04-30
  • 打赏
  • 举报
回复
看到有天天天健皇帝皇后靖靖,觉得有趣.能不能冒昧的问一下,你做的什么系统?
wangsaokui 2004-04-30
  • 打赏
  • 举报
回复
你下面的/table没有,上面的/title写错了

private void ToRight_Click(object sender, System.EventArgs e)
{
for(int i=0; i<lbox1.Items.Count;i++)
{
ListItem item=lbox1.Items[i];
if(item.Selected)
{
lbox2.Items.Add(item.Text);
lbox1.Items.Remove(item);
}
}
}

private void ToLeft_Click(object sender, System.EventArgs e)
{
for(int i=0; i<lbox2.Items.Count;i++)
{
ListItem item=lbox2.Items[i];
if(item.Selected)
{
lbox1.Items.Add(item.Text);
lbox2.Items.Remove(item);
}
}
}
tiantian1980 2004-04-30
  • 打赏
  • 举报
回复
我改后的代码,运行是空白!怪!!!!!
<% @ Page language="C#"%>
<script language="C#" runat="server">
public void ToRightList(object sender,EventArgs e)
{
for (int i=0; i<lbox1.Items.Count; i++) {
if (lbox1.Items[i].Selected)
lbox2.Items.Add(lbox1.Items[i].Text);
lbox1.Items.Remove(lbox1.Items[i].Text);
}

}
public void ToLeftList(object sender,EventArgs e)
{
for (int i=0; i<lbox2.Items.Count; i++) {
if (lbox2.Items[i].Selected)
lbox1.Items.Add(lbox2.Items[i].Text);
lbox2.Items.Remove(lbox2.Items[i].Text);
}

}
</script>
<html>
<head>
<title><title>
</head>
<body>
<b>ListBox演示</b>
<hr>
<form runat="server">
<table>
<tr>
<td>
<b>ListBox容器1:</b><br>
<asp:ListBox id="lbox1" Rows=5 SelectionMode="Multiple" runat="server">
<asp:ListItem>天天</asp:ListItem>
<asp:ListItem>天健</asp:ListItem>
<asp:ListItem>皇帝</asp:ListItem>
<asp:ListItem>皇后</asp:ListItem>
<asp:ListItem>靖靖</asp:ListItem>
</asp:ListBox>
</td>
<td>
<asp:Button id="ToRight" Text="-->" OnClick="ToRightList" runat="server"/></br>
<asp:Button id="ToLeft" Text="<--" OnClick="ToLeftList" runat="server"/>
</td>
<td>
<b>ListBox容器2:</b><br>
<asp:ListBox id="lbox2" Rows=5 SelectionMode="Multiple" runat="server"/>
</td>
</form>
</body>
</html>

wangsaokui 2004-04-30
  • 打赏
  • 举报
回复
for(int i=0; i<lbox2.Items.Count;i++)
ListItem item=lbox2.Items[i];
if(item.Selected)
{
lbox1.Items.Add(item);
lbox2.Items.Remove(item);
}
==============>
for (int i=0; i<lbox2.Items.Count; i++) {
if (lbox2.Items[i].Selected)
lbox1.Items.Add(lbox2.Items[i].Text);
lbox2.Items.Remove(lbox2.Items[i].Text);
}

兄弟,你也太懒了点吧
tiantian1980 2004-04-30
  • 打赏
  • 举报
回复
高手哪去了????????????????????????
高手哪去了????????????????????????
wangsaokui 2004-04-30
  • 打赏
  • 举报
回复
参考

void Check_Clicked(Object sender, EventArgs e) {
Message.Text="Selected Item(s):" + "<br>" + "<br>";
for (int i=0; i<checkboxlist1.Items.Count; i++) {
if (checkboxlist1.Items[i].Selected)
Message.Text=Message.Text + checkboxlist1.Items[i].Text + "<br>";
}
}
tiantian1980 2004-04-30
  • 打赏
  • 举报
回复
Line 18: ListItem item=lbox2.Items[i];
tiantian1980 2004-04-30
  • 打赏
  • 举报
回复
Compiler Error Message: CS1023: Embedded statement cannot be a declaration or labeled statement

Source Error:Line 18
wangsaokui 2004-04-30
  • 打赏
  • 举报
回复
给个出错提示嘛

62,263

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧