下拉列表selectedIndex不变 [英] Dropdownlist selectedindex not changing

查看:84
本文介绍了下拉列表selectedIndex不变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,
需要帮助下拉列表中的选定索引不会改变情况.
在我的asp.net页面中,我有四个下拉列表,只有第一个可以绑定到pageload事件中(在if(!ispostback)条件下),所有其他下拉列表只有在选择了第一个下拉列表值之后才加载. 我的问题是,第四个下拉列表的selectedIndex不变,这将在选择第三个下拉列表后绑定数据.

我觉得这是一个奇怪的问题.

萨拉斯.

先生,我已经尝试过了,但是没有解决.在第4个下拉列表中,即使在更改选择之后,回发后每次selectedindex均为1时. viewstate设置为true.


Hello,
Need help in dropdownlist selectedindex not changing situation.
In my asp.net page, I have four dropdownlists.Only the first one can be bound in pageload event (in if(!ispostback) condition).All the others are loaded only after the first dropdownlist value selected.
My problem is that the fourth dropdownlist selectedindex not changing which will bound data after the selection of third dropdownlist.

I feel this as a strange problem.

Sarath.

Sir I have tried this, but didnt solve. In 4th dropdownlist, every time selectedindex is 1 after postback, even after we change selection. viewstate is set true.


protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
        cf.Load_Dropdown(Drp_Mix, " SELECT cm.Mix_ID, cm.Mix_Name FROM CP_Mix cm ORDER BY cm.Mix_Name ", "Mix_Name", "Mix_ID");
    }
}
protected void Drp_Mix_SelectedIndexChanged(object sender, EventArgs e)
    {
         cf.Load_Dropdown(Drp_Sale_product, " SELECT distinct  cast(gpm.N_Prd_Id AS INT) AS N_Prd_Id, gpm.V_Prd_Name,V_Prd_Name+'--'+CAST(isnull(F_Prd_Tpi_Single,'') AS VARCHAR(50))+'--'+ CAST(isnull(F_Prd_Tpi_Double,'') AS VARCHAR(50)) +'--'+CAST(cast(gpm.N_Prd_Id AS INT) AS VARCHAR(30)) AS prd  " +
                                               " FROM ProductMst gpm   where gpm.V_Prd_Name LIKE '%" + Drp_Mix.SelectedItem.Text + "%' AND  cast(gpm.N_Prd_Id AS INT) > 199999 AND V_Prd_Del_Flg='N'  ORDER BY gpm.V_Prd_Name", "prd", "N_Prd_Id");
    }

protected void Drp_Sale_product_SelectedIndexChanged(object sender, EventArgs e)
    {
    Drp_Purch.Items.Clear();
            cf.Load_Dropdown(Drp_Purch, "  SELECT distinct Comp_Prd_Id,Comp_Material FROM Components gc WHERE Comp_Prd_Id='" + Drp_Sale_product.SelectedItem.Value + "'AND Comp_Material!='" + Drp_Sale_product.SelectedItem.Value + "' ", "Comp_Material", "Comp_Prd_Id");
            Drp_Purch.Items.Insert(0, "--SELECT--");
    }
//Problem in this section
 protected void Drp_Purch_SelectedIndexChanged(object sender, EventArgs e)
    {
    string s=Drp_Purch.SelectedIndex.ToString();
    }
//selectedindex always getting  1

推荐答案

亲爱的朋友
请在不使用设计窗口的aspx页面中将dropdownlist的autopostback属性设置为true
这将在大多数情况下解决问题

问候
vipin Kumar Mallaya
Dear Friend
Please set the autopostback property of the dropdownlist to true in the aspx page not using design window
This will solve the issue in most cases

Regards
vipin Kumar Mallaya


嗨Sarathpa,

检查下拉列表中的选定值.如果索引1和4的值相同,那么即使从列表中选择第4个,它也会选择第1个.

问候
Sushma
Hi Sarathpa,

Check for dropdownlist selectedvalues. If values are same for index 1 and 4 then even after select 4th from list it will select 1st.

Regards
Sushma


在下面的代码中提供dropdownlist控件中的aspx页面..



give the aspx page in dropdownlist control in below code..



<asp:dropdownlist....... xmlns:asp="#unknown">
AutoPostBack=true;</asp:dropdownlist.......>


这篇关于下拉列表selectedIndex不变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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