一个listbox中绑定数据库上的七项
我想点击其中一项到另一个页面.
点击别的项提示"请点击其它项"
请问如何实现,谢谢

解决方案 »

  1.   

    在listbox的select_indexchanged的事件中做判断。
      

  2.   

    在listbox的select_indexchanged的事件中做判断。这个我知道,可是我不知道怎么写....我是初学者,麻烦请教...
      

  3.   

    if (listBox1.SelectedIndex != -1)
                {
                    if (listBox1.Items[listBox1.SelectedIndex].ToString() == "值")
                    {
                        Form3 f = new Form3();
                        f.ShowDialog();
                    }
                    else
                    {
                        MessageBox.Show("请选择别的项!");
                    }
                }
      

  4.   

    if (listBox1.SelectedIndex != -1)
                {
                    if (listBox1.Items[listBox1.SelectedIndex].ToString() == "值")
                    {
                        Form3 f = new Form3();
                        f.ShowDialog();
                    }
                    else
                    {
                        MessageBox.Show("请选择别的项!");
                    }
                }
    这样写不对啊,有错误...
    再详细说明一下问题:一个listbox中绑定服务器数据库上的七项 
    我想点击其中第4项到A.aspx文件 
    点击别的项提示"请点击井筒项" 
      

  5.   

    if (listBox1.SelectedIndex==3) 
                { 
                    if (listBox1.Items[listBox1.SelectedIndex].ToString() == "值") 
                    { 
                        Form3 f = new Form3(); 
                        f.ShowDialog(); 
                    } 
                    else 
                    { 
                        MessageBox.Show("请选择别的项!"); 
                    } 
                } 
      

  6.   

    一个listbox中绑定服务器数据库上的七项 
    我想点击其中第4项到A.aspx页面
    点击别的项提示"请点击井筒项" 
      

  7.   

    lz写select_indexchanged事件..
    我知道在这写.可是俺不会写,555555
      

  8.   

    if (listBox1.SelectedIndex != -1) 
                { 
                    if (listBox1.SelectedIndex==4)
                    { 
     request.redirect("a.aspx"); 
                    } 
                    else 
                    { 
                        MessageBox.Show("请选择别的项!"); 
                    } 
                } 你最好写在javascript里面
      

  9.   

    为什么还是不对呢.....怎么写在javascript里面 
      

  10.   

            if (this.ListBox1.SelectedIndex != -1)
            {
                if (this.ListBox1.SelectedIndex == 4)
                {
                    Response.Redirect("CD_WELL_SOURCE.aspx");
                }
                else
    ............................我这样写的,可是点击第四项根本不管事,没反应...5555555
      

  11.   

    你没有把listbox的autopostback设置为true
      

  12.   


      MessageBox.Show("请选择别的项!");这样写有如下错误当前上下文中不存在名称“MessageBox”不能弹出.咋回事呢
      

  13.   

            if (this.ListBox1.SelectedIndex != -1)
            {
                if (this.ListBox1.SelectedIndex == 4)
                {
                    Response.Redirect("CD_WELL_SOURCE.aspx");
                }
                else
                {
                    Response.Write("<script>alert('请选择Wellbore')</script>");            }
            } 
    这样写的结果是默认选中是第5项就会到CD_WELL_SOURCE.aspx页面
    如果不是,那就弹出对话框.我要的不是这样的.我要的是点击第第5项就会到CD_WELL_SOURCE.aspx页面
    如果不是,那就弹出对话框.请哪位高人指点
      

  14.   

    这样写的结果是默认选中是第5项,点击别的都会到CD_WELL_SOURCE.aspx页面 
    如果默认不是第5项,那就弹出对话框. 我要的不是这样的. 我要的是点击第5项就会到CD_WELL_SOURCE.aspx页面 
    如果点击别的,那就弹出对话框. 麻烦请教,谢谢
      

  15.   

      this.RegisterStartupScript("hello","<script>alert('请选择别的项,fuck!')</script>");  
    这样弹
      

  16.   

    你在哪里写的上面那段代码? 
    应该在selectedindexchange事件里写
      

  17.   

    protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.ListBox1.SelectedIndex != -1)
            {
                if (this.ListBox1.SelectedIndex == 3)
                {
                    Response.Redirect("CD_WELL_SOURCE.aspx");
                }
                else
                {
                    Response.Write("<script>alert('你好,请选择Wellbore')</script>");
                                }
            }    
        }
    就是这样写的.出来结果不对.我要的是点击第5项就会到CD_WELL_SOURCE.aspx页面 
    如果点击别的,那就弹出对话框. 
      

  18.   

    前台页面
    <asp:ListBox ID="ListBox1" runat="server" AutoPostBack="True" 
            onselectedindexchanged="ListBox1_SelectedIndexChanged">
    </asp:ListBox>
    后台代码
    protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
    {
      if (this.ListBox1.SelectedIndex != -1) 
            { 
                if (this.ListBox1.SelectedIndex == 4) 
                { 
                    Response.Redirect("CD_WELL_SOURCE.aspx"); 
                } 
                else 
                { 
                    Response.Write(" <script>alert('请选择Wellbore') </script>");             } 
            } 
    }
      

  19.   

    就是这样写的....有谁加我QQ说呢?QQ号:38679275....谢谢各位了
      

  20.   

    Response.Write(" <script>alert('请选择Wellbore'); </script>"); 
    加个 ;^o^
      

  21.   

    程序没有问题了,只是结果不是我想要的上面程序的运行结果是:默认选中是第5项,点击别的都会到CD_WELL_SOURCE.aspx页面 
    如果默认不是第5项,那就弹出对话框. 我要的不是这样的. 我要的是点击第5项就会到CD_WELL_SOURCE.aspx页面 
    如果点击别项,那就弹出对话框. 
      

  22.   

    if (listBox1.SelectedIndex==4) 也就是这句的问题,这个是默认第五项.
    但是我想要的是点击这一顶能进那个页面,点击别的弹出对话框
      

  23.   

     if (this.ListBox1.SelectedIndex != -1) 
            { 
                if (this.ListBox1.SelectedIndex == 4) 
                { 
                    Response.Redirect("A.aspx"); 
                } 
                else 
                { 
                    Response.Write("<script>alert('请选择其他项'); </script>");             } 
            }
      

  24.   

    这算是页面传值的一个应用了。我习惯于windowform的,给个windowform的参考给你吧。
    from1事件代码:
    string str ;
    str=ListBox1选择项的值
    form2 ff=new form(str);
    ff.show();
    form2代码,也就是重写form2的构造函数:
      public form2(string ss)
            {
                InitializeComponent();
                tbcantai.Text = ss;
            }
    这样就可以将form1中要传的值传给form2中接受值的控件,我想在web程序中也是这个思路吧!
      

  25.   

    在listbox的select_indexchanged的事件中做判断。 
    很简单