下拉菜单无法正常工作 [英] DropDown Not Working Correctly

查看:80
本文介绍了下拉菜单无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.


这篇关于下拉菜单无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆