drowdownlist的数据并不是从数据库中取出来的,是在代码里加上的,而且还要实现两个drowdownlist都有个空的情况,drowdownlist1选空的话,drowdownlis2变为空,能帮我写一个吗?!!!!!!!! 我搜了无数个例子都不行,所以来麻烦大家了!drowpdownlist1的值:
空,A,B
dropdowlist2:
空,
A:aaa,bbb
B:ccc,ddd
就是这个效果
哪位大哥抽空帮我做个完整的例子行吗???!(vb.net)分不够在加
(不要javascript实现的那种,必须用dropdownlist)

解决方案 »

  1.   

    dropdownlist改变值后直接提交吗?如果是那不是很容易在服务器端实现吗?
      

  2.   

    为什么不自己想一下呢?散点分就想人家给你个完整的实例也太懒了吧。我做过类似的程序,不过,我是从数据库中提取数据的。有2个Combo,一个是票证种类列表,一个是字轨列表,要根据票证种类列表中选择指定的票证类别才能填写字轨列表的Combo,我的实现方法是截取票证种类Combo的变更选择事件填写字轨列表事件,这个有个不好的地方就是每变更一次页面都会被post一次,具体怎么实现你可以自己考虑一下。
      

  3.   

    其实这个很简单的,只要把DropDownList1下拉框AutoPostBack设置为True,然后在他的SelectedIndexChanged事件中写相应的DropDownList2就行了,我是按照你的要求做了个简单的示例,希望对你有帮助.不过依靠别人给出完全的代码始终不是很好的解决办法Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            If Not Page.IsPostBack Then
                Dim listitem As ListItem
                listitem = New ListItem()
                listitem.Text = ""
                DropDownList1.Items.Add(listitem)
                listitem = New ListItem()
                listitem.Text = "A"
                DropDownList1.Items.Add(listitem)
                listitem = New ListItem()
                listitem.Text = "B"
                DropDownList1.Items.Add(listitem)
            End If
        End SubPrivate Sub DropDownList1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
            DropDownList2.Items.Clear()
            Dim listitem As ListItem
            Select Case DropDownList1.SelectedItem.Text
                Case ""
                    listitem = New ListItem()
                    listitem.Text = ""
                    DropDownList2.Items.Add(listitem)
                Case "A"
                    listitem = New ListItem()
                    listitem.Text = "aaa"
                    DropDownList2.Items.Add(listitem)
                    listitem = New ListItem()
                    listitem.Text = "bbb"
                    DropDownList2.Items.Add(listitem)
                Case "B"
                    listitem = New ListItem()
                    listitem.Text = "ccc"
                    DropDownList2.Items.Add(listitem)
                    listitem = New ListItem()
                    listitem.Text = "ddd"
                    DropDownList2.Items.Add(listitem)
            End Select
        End Sub
      

  4.   

    is there have csharp's code?
      

  5.   

    不知道是不是你的要求WebForm1.aspx:<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" Src="WebForm1.aspx.vb" Inherits="WebForm1"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <title>WebForm1</title>
    <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
    <meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
    <meta name="vs_defaultClientScript" content="JavaScript">
    <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
    </HEAD>
    <body>
    <form id="Form1" method="post" runat="server">
    <FONT face="宋体">
    <asp:DropDownList id="DropDownList1" runat="server" AutoPostBack="True"></asp:DropDownList>
    <asp:DropDownList id="DropDownList2" runat="server"></asp:DropDownList>
    <asp:Button id="Button1" runat="server" Text="Button"></asp:Button></FONT>
    </form>
    </body>
    </HTML>WebForm1.aspx.vbImports System.Collections
    Imports System.Web.UI.WebControls
    Public Class WebForm1
        Inherits System.Web.UI.Page#Region " Web 窗体设计器生成的代码 "    '该调用是 Web 窗体设计器所必需的。
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()    End Sub
        Protected WithEvents Button1 As System.Web.UI.WebControls.Button
        Protected WithEvents DropDownList1 As System.Web.UI.WebControls.DropDownList
        Protected WithEvents DropDownList2 As System.Web.UI.WebControls.DropDownList    '注意: 以下占位符声明是 Web 窗体设计器所必需的。
        '不要删除或移动它。
        Private designerPlaceholderDeclaration As System.Object    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
            'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
            '不要使用代码编辑器修改它。
            InitializeComponent()
        End Sub#End Region    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            '在此处放置初始化页的用户代码
            If Not Page.IsPostBack Then
                DropDataBind()
            End If
        End Sub    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click    End Sub    Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
            If Me.DropDownList1.SelectedValue.Trim() = "" Then
                Me.DropDownList2.SelectedIndex = 0
            ElseIf Me.DropDownList1.SelectedValue.Trim() = "A" Then
                Me.DropDownList2.SelectedIndex = 1
            ElseIf Me.DropDownList1.SelectedValue.Trim() = "B" Then
                Me.DropDownList2.SelectedIndex = 2
            End If    End Sub
        Private Sub DropDataBind()
            With Me.DropDownList1
                .Items.Add(New ListItem(" ", ""))
                .Items.Add(New ListItem("A", "A"))
                .Items.Add(New ListItem("B", "B"))
            End With
            With Me.DropDownList2
                .Items.Add(New ListItem(" ", ""))
                .Items.Add(New ListItem("aaa", "aaa"))
                .Items.Add(New ListItem("bbb", "bbb"))
            End With
        End Sub
    End Class
    ----------------------------------------------------------------------
    欢迎试用ASP.NET大文件上传组件(UpLoadModule 1.1.2004.0720 & 无刷新进度条)
    http://www.cnblogs.com/lion.net/archive/2004/07/20/25987.aspx
    UpLoadModule为您提供了这样的一个方案,该方案除了允许你上传大文件外,还能实时显示上传进度并捕获上传中的错误信息。允许无商业目的个人用户免费使用。
    ----------------------------------------------------------------------
    欢迎试用HtmlEditor(在线文本编辑器)
    http://www.cnblogs.com/lion.net/archive/2004/07/15/24296.aspx
    她是一个网页的在线文本编辑器,她能够在网页上实现许多桌面编辑软件(如:Word)所具有的强大可视编辑功能;她是一个真正的绿色软件,不需要在计算机上安装任何的客户端软件;并且她是完全开放源代码的,允许无商业目的个人用户免费使用。
    ----------------------------------------------------------------------
      

  6.   

    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 WA1
    {
    public struct Jeng
    {
    private string ahmy1;
    private string ahmy2; public string Ahmy1
    {get{return this.ahmy1;}}
    public string Ahmy2
    {get{return this.ahmy2;}}
    public Jeng(string a,string b)
    {
    ahmy1 = a;
    ahmy2=b;
    }
    }
    /// <summary>
    /// Summary description for WebForm1.
    /// </summary>
    public class WebForm1 : System.Web.UI.Page
    {
    protected System.Web.UI.WebControls.DropDownList DropDownList1;
    protected System.Web.UI.WebControls.DropDownList DropDownList2;
    ArrayList ls1 = new ArrayList();
    ArrayList ls2 = new ArrayList();

    private void Page_Load(object sender, System.EventArgs e)
    {
    if(!IsPostBack)
    {

    ls1.Add(new Jeng("a1","a1"));
    ls1.Add(new Jeng("a2","a2"));
    ls1.Add(new Jeng("a3","a3"));
    ls1.Add(new Jeng("a4","a4"));
    ls1.Add(new Jeng("a5","a5"));
    this.DropDownList1.DataSource = ls1;
    this.DropDownList1.DataBind();
    this.DropDownList1.AutoPostBack = true; ls2.Add(new Jeng("b1","b1"));
    ls2.Add(new Jeng("b0","b0"));
    this.DropDownList2.DataSource = ls2;
    this.DropDownList2.DataBind(); //DropDownList2.DataSource = ls;
    //DropDownList2.DataBind();
    }

    } #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.DropDownList1.SelectedIndexChanged += new System.EventHandler(this.DropDownList1_SelectedIndexChanged);
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
    {
    //ls.Clear();
    if(DropDownList1.SelectedValue=="a1")
    {
    ls2.Clear();
    ls2.Add(new Jeng("b1","b1"));
    ls2.Add(new Jeng("b0","b0"));
    this.DropDownList2.DataSource = ls2;
    this.DropDownList2.DataBind();
    }
    else
    {
    ls2.Clear();
    ls2.Add(new Jeng("b2","b2"));
    ls2.Add(new Jeng("b3","b3"));
    this.DropDownList2.DataSource = ls2;
    this.DropDownList2.DataBind();
    }


    }
    }
    }
    //以上是.cs文件
    //以下是aspx文件
    //原谅我没有用vb
      

  7.   

    <%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="WA1.WebForm1" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <HTML>
    <HEAD>
    <title>WebForm1</title>
    <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
    <meta name="CODE_LANGUAGE" Content="C#">
    <meta name="vs_defaultClientScript" content="JavaScript">
    <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
    </HEAD>
    <body MS_POSITIONING="GridLayout">
    <form id="Form1" method="post" runat="server">
    <FONT face="宋体">
    <asp:DropDownList id="DropDownList1" DataTextField="ahmy1" DataValueField="ahmy2" runat="server"></asp:DropDownList>
    <asp:DropDownList id="DropDownList2" DataTextField="ahmy1" DataValueField="ahmy2" runat="server"></asp:DropDownList></FONT>
    </form>
    </body>
    </HTML>
      

  8.   

    ddl1.items.add("");
    ddl1.items.add("A");
    ddl1.items.add("B");
    ddl1.selectedindex=ddl1.items.indexof(ddl1.items.findbytext(""));ddl2.items.add("");
    ddl2.items.add("aaa,bbb");
    ddl2.items.add("ccc,ddd");
    ddl2.selectedindex=ddl2.items.indexof(ddl2.items.findbytext(""));ddl1_selectedindexchanged()中
    if (ddl1.selecteditems.text=="")
    ddl2.selecteditems.text="";