dropdown SelectedIndexChanged页面重新加载但值为null [英] dropdown SelectedIndexChanged page reload but value null

查看:81
本文介绍了dropdown SelectedIndexChanged页面重新加载但值为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




i有2个下拉列表,onselectedindexchanged和autopostback true



当我点击dropdown1页面重新加载时,当前选择listitem是selectbox中的默认值..,我根据dropdown1值从数据库填充dropdown2 ..

然后当我点击dropdown2时,页面重新加载但是dropdown2选择的索引保持为0或空白





什么是错误





Hi
i have 2 dropdown with onselectedindexchanged and autopostback true

when i click dropdown1 the page reloads ,and current select listitem is default in selectbox.., i fill dropdown2 from database depending on dropdown1 value..
then when i click dropdown2 ,page reloads but the dropdown2 selected index remains 0 or blank


what is error


<asp:DropDownList ID="DropCity"  AutoPostBack="True"   onselectedindexchanged="DropCity_SelectedIndexChanged"   runat="server" >
                    </asp:DropDownList>













<asp:DropDownList ID="DropCity1"  AutoPostBack="True"   onselectedindexchanged="DropCity1_SelectedIndexChanged"   runat="server" >
                    </asp:DropDownList>













protected void DropCity1_SelectedIndexChanged(object sender, EventArgs e)
  {





DropCity.DataSource();

DropCity.databing();







}





DropCity.DataSource();
DropCity.databing();



}

protected void DropCity_SelectedIndexChanged(object sender, EventArgs e)
    {







}





请建议




}


please advice

推荐答案

在drp1的SelectedIndexChanged事件中将值绑定到drp2 ..

如果你没有对drp2索引改变事件进行任何操作,那么设置autopostback =false



使用以下属性





Bind the values to drp2 in drp1's SelectedIndexChanged event..
If you not doing any operation on drp2 index changed event then set autopostback = "false"

make use of properties as below


drp1.DataTextField = "Test1";
               drp1.DataValueField = "TestID";
               drp1.DataSource = dt;

               drp1.DataBind();


为dropcity1设置autopostback = fasle
set autopostback =fasle for dropcity1


你好
i解决了..我在DropCountry中检查,如果Dropcity为null,则只填充它..

所以现在运行
Hi i solved it.. i check in DropCountry , if Dropcity is null ,then only fill it..
so this runs now


这篇关于dropdown SelectedIndexChanged页面重新加载但值为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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