DropDownList的选定值没有改变? [英] dropdownlist selected value is not changing?

查看:129
本文介绍了DropDownList的选定值没有改变?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

DropDownList的选择值不发生变化。虽然字符串_month也含有的价值,但DropDownList的是没有得到it.all其他都工作正常,但只有ddlMonth.selected值不changing.i已指定_month价值,但它不改变,为什么?只有ddlMonth是不会改变所有其它的原因ddlmonth是不会改变工作正常?

 如果(_objMonth.Contains(月))
{
    字符串_Month =(字符串)_objMonth.GetData(月);
    ddlMonth.SelectedValue = _Month;
    ///这里ddlMonth.selected价值没有得到来自_month新的价值
}

其他code低于

 保护无效的Page_Load(对象发件人,发送System.EventArgs)
{
   如果(Page.IsPostBack)
       返回;
   尝试
   {
       负载();
       GetYears();
       如果(!string.IsNullOrEmpty(ddlYear.SelectedValue))
       hYearId.Value = ddlYear.SelectedValue;
       GetPeriods(Convert.ToInt32(hYearId.Value));
       GetDepartment();
       GetSection();       #地区都被选择登录用户部门和部分
       ddldepartment.SelectedValue = CommonMethods.UserContext.EmployeeDeparmentID;
       ddlSection.SelectedValue = CommonMethods.UserContext.EmployeeSectionID;       #endregion       ddldepartment_SelectedIndexChanged(NULL,NULL);
       ddlemp_SelectedIndexChanged(NULL,NULL);
       字符串名称=的Request.QueryString [ID]作为字符串;       #地区创建Cache对象       的ICacheManager _objYear = CacheFactory.GetCacheManager(); //创建缓存对象
       的ICacheManager _objMonth = CacheFactory.GetCacheManager(); //创建缓存对象
       的ICacheManager _objDepartment = CacheFactory.GetCacheManager(); //创建缓存对象
       的ICacheManager _objSection = CacheFactory.GetCacheManager(); //创建缓存对象
       #endregion    如果(的Request.QueryString [ClickTag会]!= NULL)
    {
       #区域设置缓存的项目
       如果(的Request.QueryString [ClickTag会]。的ToString()==1)
       {
          如果(_objYear.Contains(年))
          {
             字符串_Year =(字符串)_objYear.GetData(年);
             ddlYear.SelectedValue = _Year;
          }
          如果(_objMonth.Contains(月))
          {
             字符串_Month =(字符串)_objMonth.GetData(月);
             ddlMonth.SelectedValue = _Month;
          }
          如果(_objDepartment.Contains(部))
          {
             字符串_Department =(字符串)_objDepartment.GetData(部);
             ddldepartment.SelectedValue = _Department;
          }
          如果(_objSection.Contains(科))
          {
             字符串_Section =(字符串)_objSection.GetData(科);
             ddlSection.SelectedValue = _Section;
          }
       }
       #endregion
    }保护无效ddlMonth_SelectedIndexChanged(对象发件人,EventArgs的发送)
{
   尝试
   {
      如果(!string.IsNullOrEmpty(ddlMonth.SelectedValue))
      {
         hClpid.Value = ddlMonth.SelectedValue.Split(,)[0];
         会话[开始日期] = ddlMonth.SelectedValue.Split(,)[2];
         会话[结束日期] = ddlMonth.SelectedValue.Split(,)[3];
         ddldepartment_SelectedIndexChanged(NULL,NULL);
         ddlemp_SelectedIndexChanged(NULL,NULL);
         如果(ddlSection.SelectedIndex大于0)
            ddlSection_SelectedIndexChanged(NULL,NULL);
      }
   }无效GetPeriods(INT _year)
{
     IBLCal​​enderPeriod _bl =(IBLCal​​enderPeriod)SetupBLFactory.GetCalenderPeriod();     数据集_ds =(数据集)_bl.GetPeriodIdsByYear(_year).GetMaster();     _ds.Tables [0] .Columns.Add(ID);     的foreach(在_ds.Tables的DataRow _dr [0] .Rows)
     {
          _dr [ID] = _dr [CLP_ID] +,+ _dr [clp_activeperiod] +,+ _dr [CLP_DATESTART] +,+ _dr [CLP_DATEEND] +;     }
     ddlMonth.DataSource = _ds.Tables [0];
     ddlMonth.DataTextField =CLP_DESCRIPTION;
     ddlMonth.DataValueField =ID;
     ddlMonth.DataBind();     的foreach(在_ds.Tables的DataRow _dr [0] .Rows)
     {
          如果(_dr [clp_activeperiod]!= NULL)
          如果(_dr [clp_activeperiod]。的ToString()==1)
          {
             ddlMonth.SelectedValue = _dr [ID]的ToString()。
             hClpid.Value = ddlMonth.SelectedValue.Split(,)[0];
             会话[开始日期] = ddlMonth.SelectedValue.Split(,)[2];
             会话[结束日期] = ddlMonth.SelectedValue.Split(,)[3];
             打破;
          }
          其他
          {
             ddlMonth.SelectedIndex = 0;
             hClpid.Value =0;
          }
     }
}


解决方案

我觉得你在设置,但ddlMonth一个ddlMonth值不具有绑定值..尝试值设置为之前绑定在你的ddlMonth值列表它

dropdownlist selected value is not changing. although the string _month also contain the value but dropdownlist is not getting it.all other are working fine but only ddlMonth.selected value is not changing.i have assigned _month value to it but its not changing why? only ddlMonth is not changing all other are working fine why ddlmonth is not changing?

if (_objMonth.Contains("Month"))
{
    string _Month = (string)_objMonth.GetData("Month");
    ddlMonth.SelectedValue = _Month; 
    ///here ddlMonth.selected value is not getting new value from _month
}

Other code is below

protected void Page_Load(object sender, System.EventArgs e)
{
   if (Page.IsPostBack)
       return;
   try
   {
       OnLoad();
       GetYears();
       if (!string.IsNullOrEmpty(ddlYear.SelectedValue))
       hYearId.Value = ddlYear.SelectedValue;
       GetPeriods(Convert.ToInt32(hYearId.Value));
       GetDepartment();
       GetSection();

       #region Get Selected login user department and section
       ddldepartment.SelectedValue = CommonMethods.UserContext.EmployeeDeparmentID;
       ddlSection.SelectedValue = CommonMethods.UserContext.EmployeeSectionID;

       #endregion

       ddldepartment_SelectedIndexChanged(null, null);
       ddlemp_SelectedIndexChanged(null, null);
       string name = Request.QueryString["id"] as string;

       #region Create Cache object

       ICacheManager _objYear = CacheFactory.GetCacheManager();//Create cache object
       ICacheManager _objMonth = CacheFactory.GetCacheManager();//Create cache object
       ICacheManager _objDepartment = CacheFactory.GetCacheManager();//Create cache object
       ICacheManager _objSection = CacheFactory.GetCacheManager();//Create cache object
       #endregion

    if (Request.QueryString["ClickTag"]!=null)
    {
       #region set Cached items
       if (Request.QueryString["ClickTag"].ToString() == "1")
       {
          if (_objYear.Contains("Year"))
          {
             string _Year = (string)_objYear.GetData("Year");
             ddlYear.SelectedValue = _Year;
          }
          if (_objMonth.Contains("Month"))
          {
             string _Month = (string)_objMonth.GetData("Month");
             ddlMonth.SelectedValue= _Month;
          }
          if (_objDepartment.Contains("Department"))
          {
             string _Department = (string)_objDepartment.GetData("Department");
             ddldepartment.SelectedValue= _Department;
          }
          if (_objSection.Contains("Section"))
          {
             string _Section = (string)_objSection.GetData("Section");
             ddlSection.SelectedValue = _Section;
          }
       }
       #endregion
    }

protected void ddlMonth_SelectedIndexChanged(object sender, EventArgs e)
{
   try
   {
      if (!string.IsNullOrEmpty(ddlMonth.SelectedValue))
      {
         hClpid.Value = ddlMonth.SelectedValue.Split(',')[0];
         Session["Startdate"] = ddlMonth.SelectedValue.Split(',')[2];
         Session["EndDate"] = ddlMonth.SelectedValue.Split(',')[3];
         ddldepartment_SelectedIndexChanged(null, null);
         ddlemp_SelectedIndexChanged(null, null);
         if (ddlSection.SelectedIndex > 0)
            ddlSection_SelectedIndexChanged(null, null);
      }
   }

void GetPeriods(int _year)
{
     IBLCalenderPeriod _bl = (IBLCalenderPeriod)SetupBLFactory.GetCalenderPeriod();

     DataSet _ds = (DataSet)_bl.GetPeriodIdsByYear(_year).GetMaster();

     _ds.Tables[0].Columns.Add("ID");

     foreach (DataRow _dr in _ds.Tables[0].Rows)
     {
          _dr["ID"] = _dr["CLP_ID"] + "," + _dr["clp_activeperiod"] + "," + _dr["CLP_DATESTART"] + "," + _dr["CLP_DATEEND"] + "";

     }
     ddlMonth.DataSource = _ds.Tables[0];
     ddlMonth.DataTextField = "CLP_DESCRIPTION";
     ddlMonth.DataValueField = "ID";
     ddlMonth.DataBind();

     foreach (DataRow _dr in _ds.Tables[0].Rows)
     {
          if (_dr["clp_activeperiod"] != null)
          if (_dr["clp_activeperiod"].ToString() == "1")
          {
             ddlMonth.SelectedValue = _dr["ID"].ToString();
             hClpid.Value = ddlMonth.SelectedValue.Split(',')[0];
             Session["Startdate"] = ddlMonth.SelectedValue.Split(',')[2];
             Session["EndDate"] = ddlMonth.SelectedValue.Split(',')[3];
             break;
          }
          else
          {
             ddlMonth.SelectedIndex = 0;
             hClpid.Value = "0";
          }
     }
}

解决方案

I think you are setting a value in ddlMonth but ddlMonth do not have that binded value.. Try to bind list of values in your ddlMonth before setting a value to it

这篇关于DropDownList的选定值没有改变?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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