Compiler Error Message: CS1023: Embedded statement cannot be a declaration or labeled statementSource Error:Line 18

解决方案 »

  1.   

    Line 18:         ListItem item=lbox2.Items[i];
      

  2.   

    参考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>";
              }
           }
      

  3.   

    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);
    }兄弟,你也太懒了点吧
      

  4.   

    我改后的代码,运行是空白!怪!!!!!
    <% @ 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>
      

  5.   

    你下面的/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);
    }
    }
    }
      

  6.   

    前台:
    <%@ 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>
      

  7.   

    后台:
    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);
    }
    }
    }
    }
    }
      

  8.   

    哪位仁兄,解释下前台后台,不懂!
    我一直就一下就运行出来!
    回复人: wangsaokui(无间道II(前传)) 分一定给!就今12点前吧!
      

  9.   

    晚了,兄弟!前台就是你的页面,文件名后缀为aspx
    后台就是你的代码,文件名后缀为aspx.vb或aspx.cs