0

我想刷新网络表单中的下拉列表。我放了

<asp:DropDownList 
  ID="ddlNewJobOrder" 
  DataTextField="name" 
  DataValueField="value"
  runat="server" 
  AppendDataBoundItems="True" 
  DataSourceID="NewJobOrderDS" 
  ToolTip="New Job Order List" 
  Width="110" 
  AutoPostBack="True" 
  OnSelectedIndexChanged="ddlNewJobOrder_SelectedIndexChanged">
 </asp:DropDownList>

 ddlNewJobOrder.DataBind();

但它不起作用。

4

2 回答 2

2

DataSourceID还不够。它不是“必须”的属性。您需要的属性是DataSource. 在服务器端,创建一个包含您要添加的数据的对象并执行

ddlNewJobOrder.DataSource = dataObject;
ddlNewJobOrder.DataBind();
于 2013-08-12T08:36:17.613 回答
0
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="Sql_dalei" DataTextField="name1" DataValueField="flag1" AutoPostBack="True" OnSelectedIndexChanged="zhonglei_SelectedIndexChanged"></asp:DropDownList>

<asp:SqlDataSource ID="Sql_dalei" runat="server" 
ConnectionString="<%$ ConnectionStrings:SignBoardConnectionString%>"
SelectCommand="SELECT * FROM [TestCodeClass1]"></asp:SqlDataSource>

<asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="Sql_zhonglei" DataTextField="name2" DataValueField="flag2" AutoPostBack="True" OnSelectedIndexChanged="nmnm_SelectedIndexChanged">
</asp:DropDownList>

<asp:SqlDataSource ID="Sql_zhonglei" runat="server"
 ConnectionString="<%$ ConnectionStrings:SignBoardConnectionString %>"
SelectCommand="SELECT * FROM [TestCodeClass2]"></asp:SqlDataSource>

----------------------------------------------------------------------------

 protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            DropDownList1.DataBind();
            DropDownList1.Items.Insert(0, new ListItem { Text = "大類名稱", Value = "0" });
            DropDownList1.SelectedItem.Selected = true;
            tet.Attributes["class"] = "s2";
        }
    }

protected void zhonglei_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (DropDownList1.SelectedIndex != 0)
        {
            DropDownList2.Items.Clear();
            String s = DropDownList2.SelectedValue;
            Sql_zhonglei.SelectCommand = "SELECT * FROM [TestCodeClass2] where preflag1='" + DropDownList1.SelectedIndex + "'";
            DropDownList2.DataBind();
            DropDownList2.Items.Insert(0, new ListItem { Text = "中類名稱", Value = "0" });
            tett.Attributes["class"] = "s2";
            tett2.Attributes["class"] = "s";
            if (DropDownList2.SelectedValue == "")
            {
                tett.Attributes["class"] = "s";


            }

        }
        else
        {
            tett.Attributes["class"] = "s";
            tett2.Attributes["class"] = "s";
        }

    }
于 2017-09-05T05:43:46.250 回答