下拉菜单无法正常工作

问题描述:

我绑定了我的下拉菜单,这是我的代码

i have binded my drop down here is my code

public void FillDll()
    {
        if (!Page.IsPostBack)
        {
            DataTable droomtype = (DataTable)ViewState["GridView"];
            if (droomtype.Rows[0]["Single"].ToString() != "")
                DdlRoomType.Items.Add(new ListItem("Single", droomtype.Rows[0]["Single"].ToString()));
            if (droomtype.Rows[0]["Double"].ToString() != "")
                DdlRoomType.Items.Add(new ListItem("Double", droomtype.Rows[0]["Double"].ToString()));
            if (droomtype.Rows[0]["Triple"].ToString() != "")
                DdlRoomType.Items.Add(new ListItem("Triple", droomtype.Rows[0]["Triple"].ToString()));
            if (droomtype.Rows[0]["Quad"].ToString() != "")
                DdlRoomType.Items.Add(new ListItem("Quad", droomtype.Rows[0]["Quad"].ToString()));
            if (droomtype.Rows[0]["Twin"].ToString() != "")
                DdlRoomType.Items.Add(new ListItem("Twin", droomtype.Rows[0]["Twin"].ToString()));
            //DdlRoomType.Attributes.Add("onChange", "getDropDownListvalue('" + dp.ClientID + "','" + lblprice2.ClientID + "')");
            //DdlRoomType.Attributes.Add("onChange", "getDropDownListvalue('" + DdlRoomType.ClientID + "','" + lbl_asianprice.ClientID + "')");
            //DdlRoomType.Items.Insert(0, "---Select One---");
            //DdlRoomType.SelectedIndex = 0;
            //DdlRoomType.Attributes.Add("onChange", "getDropDownListvalue('" + DdlRoomType.ClientID + "')");
        }
    }


我已启用其autopost属性为true,因为在indexchange上,我想将价格与标签绑定,当我选择任何要绑定标签的项目时遇到问题,但是默认情况下再次选择第一个,我不知道我在哪里做错了帮助我


i have enabled its autopost property true because on indexchange i want to bind a price with label i m getting a problem when i select any of the item the label is binded but again by default 1st is being selected i dont know where i have done mistake kindly help me out

在您的代码中,您正在检查页面是否不是回发.如果不是回发,它将执行if语句中的代码.

因此,如果在更改选定的索引之后调用上述方法,请确保删除if条件.请参阅 http://msdn.microsoft.com/en-us/library /system.web.ui.page.ispostback.aspx

绑定之后,我建议将所选索引设置为-1,以便不选择任何项目.
In your code, you are checking if the page is not a postback. If its not a postback, it will execute the code in the if statement.

Therefore, if you''re calling the above method after the selected index change, make sure to remove the if condition. See http://msdn.microsoft.com/en-us/library/system.web.ui.page.ispostback.aspx

After the binding, I would suggest to set the selected index to -1 in order not to have any item selected.