2014-01-23 4 views
1

드롭 다운 목록에서 선택한 값이 변경되지 않습니다. 문자열 _month에도 값이 포함되어 있지만 dropdownlist가 it.all을 모두 가져 오지는 않습니다. 다른 모든 것은 잘 작동하지만 ddlMonth.selected 값만 change.i에 _month 값을 할당했지만 그 이유는 변경하지 않았습니까? ddlMonth 만 변경되지 않으면 ddlmonth가 변경되지 않는 이유는 무엇입니까?드롭 다운 목록에서 선택한 값이 변경되지 않습니까?

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

다른 코드는

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"; 
      } 
    } 
} 
+0

새 값을 선택할 수 없습니다. 그 바운드 데이터에 있지 않습니다 –

답변

0

하십시오 다음 형식 아래에 게시하기 전에 코드입니다. 설명은의를 Page_Load가 실행 한 때문에 문제에 대한 나는 솔루션은 당신이 당신이 페이지 수명주기에 대한 문서를 살펴보고 제안

if(!isPostback){...} 

내부의 SelectedValue를 설정 지역을 넣어 생각 페이지를 처음으로로드 할 때뿐만 아니라 모든 포스트 백에 대해서도 (if (! isPostback) {...}을 사용하지 않는 경우)

1

ddlMonth에 값을 설정한다고 생각하지만 ddlMonth는 그렇지 않습니다. 바인딩 된 값이 있습니다. 값을 설정하기 전에 ddlMonth의 값 목록을 바인딩하십시오.

+0

젠체하는 사람 여기 바인딩 된 및 페이지로드에 잘 작동하지만 다른 페이지로 이동하고 거기에 다시 단추가 있고 다른 페이지에서 뒤로 단추를 클릭 할 때 cacheitemss 메서드를 사용했습니다. 다른 모든 것은 잘 작동합니다 ddlmonth.selectedValue = _Month here 여기에도 _month에는 새로운 값이 있지만 ddlmonth.selectedValue는 _Month에서 가져 오지 않습니다 여기 Month = 3,0,9/1/2013 12:00 : 00 AM, 9/30/2013 12:00:00 AM 및 ddlmonth.selectedValue = 7,0,1/1/2014 12:00:00 AM, 1/31/2014 12:00:00 AM –

관련 문제