Dropdownlist2不更改textBox值?

时间:2015-11-30 09:30:59

标签: c# asp.net

我想在我选择dropdown1而不是dropdown2时选择dropdownlist2文本框更改后更改我的文本框,我的意思是当我选择dropdown2列表项时我想要textBox9更改

这是我背后的代码

public static void main(String[] args) {

    ObjectMapper om = new ObjectMapper();
    InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("test.json");
    try {
        JsonNode node = om.readValue(in, JsonNode.class).get("results");
        NodeFilteringConsumer consumer = new NodeFilteringConsumer(new NodeFilter() {

            @Override
            public boolean apply(JsonNode node) {
                //Filter for node with values greater than 20.
                return node.get("values").asDouble() > 20;
            }
        });

        node.forEach(consumer);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

public static interface NodeFilter{

    boolean apply(JsonNode node);
}

public static class NodeFilteringConsumer implements Consumer<JsonNode>{

    private NodeFilter f;

    public NodeFilteringConsumer(NodeFilter f) {
        this.f = f;
    }


    @Override
    public void accept(JsonNode t) {
        if (f.apply(t)){
            //Only filtered records reach here
            System.out.println("Filter applied on node:" + t);
        }
    }

}

1 个答案:

答案 0 :(得分:0)

问题,您在其事件hadnler中从items删除DropDownList2,然后通过调用方法LoadOptions1()重新绑定项目。此删除和重新绑定将删除所选的DropDownList2索引。简而言之,您在DropDownList2中没有选择任何值。

您应该DropDownList1事件处理程序中执行此重新绑定,而不是在DropDownList2中执行此操作。

您的代码很好,只需从处理程序DropDownList2_SelectedIndexChanged中删除这些行:

protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
    DropDownList2.Items.Clear();       //remove
    LoadOptions1();                    //remove

    string selected2 = DropDownList2.SelectedItem.Value;
    DropDownList2.Visible = true;      //remove
    //...