2013-10-16 60 views
0

我需要幫助瞭解爲什麼一些formview內部的控件在運行時填充後會在回發後丟失其內容。如果dropdownlist在formview中並且在運行時被填充,它在回發後不會保留值

我有一個dropdownlist(ddl_1),我根據來自另一個dropdownlist(ddl_2)在同一formview中的條目填充。所有似乎工作正常使用回發事件發生之後,新填充的下拉列表(ddl_1)爲空。

這兩個ddls的EnableViewState設置爲true。 ddl_2是databound,但ddl_1不是。在IsPostBack子句中的Page_Load中,ddl_2是數據綁定,然後我調用填充ddl_1的函數。

如果我將ddl_1移到formview之外,它會在回發後保留其條目。

另一個類似的問題是在formview裏面有一個TextBox。在插入模式下,回發後TextBox的內容消失。儘管這在插入模式下不會發生。

什麼是特定於造成這種情況的formview?

非常感謝。

這是Page_load代碼。

保護小組的Page_Load(BYVAL發件人爲對象,BYVALË作爲System.EventArgs)把手Me.Load

If Not IsPostBack Then 

     If NavHelper.User.UserName = "" Then 
      Dim UserIP As String 
      Dim UserLogin As String 
      Dim UserEmail As String 
      UserIP = HttpContext.Current.Request.UserHostAddress 
      UserLogin = HttpContext.Current.Session("Username") 
      UserEmail = HttpContext.Current.Session("Email") 
      GetUserInfo() 

      CurrentRFQ = Nothing 
      If NavHelper.RFQ.ID = -1 Then 
       formview_RFQ.ChangeMode(FormViewMode.Insert) 
       tabpanelCustomerParts.Visible = False 
       tabpanelDocuments.Visible = False 
       tabpanelReviews.Visible = False 
       tabpanelRFQReviewHistory.Visible = False 
       listview_CustomerParts.Dispose() 

      Else 
       formview_RFQ.ChangeMode(FormViewMode.Edit) 
       listview_ReviewContracts_Initial.EditIndex = 0 
       SessionHelper.CurrentObject = TAA.Library.RFQ.GetObject(NavHelper.RFQ.ID) 
       mRFQ = DirectCast(SessionHelper.CurrentObject, TAA.Library.RFQ) 
       Dim UserdeptTotal As Long 
       UserdeptTotal = HttpContext.Current.Session("DepartmentTotal") 
       If formview_RFQ.FindControl("ddlCompanyBuyerNVList") IsNot Nothing Then 
        Dim ddl As DropDownList = DirectCast(formview_RFQ.FindControl("ddlCompanyBuyerNVList"), DropDownList) 
        FillCompanyNameDropDownList(ddl) 
       End If 
       tabpanelCustomerParts.Visible = True 
       tabpanelDocuments.Visible = True 
       tabpanelReviews.Visible = True 
       tabpanelRFQReviewHistory.Visible = True 
       If NavHelper.RFQ.Copy = True Then 
        SetModifyCopy() 
       End If 
      End If 
     Else 'IsPostBack 
      datasource_BuyerNVList.Dispose() 
      datasource_BuyerNVList.DataBind()    
      Dim ddl As DropDownList 
      If (formview_RFQ.CurrentMode = FormViewMode.Insert) Then 
       ddl = DirectCast(formview_RFQ.FindControl("ddlCompanyBuyerNVListInsert"), DropDownList) 
      ElseIf formview_RFQ.FindControl("ddlCompanyBuyerNVList") IsNot Nothing Then 
       ddl = DirectCast(formview_RFQ.FindControl("ddlCompanyBuyerNVList"), DropDownList) 
      End If 
      FillCompanyNameDropDownList(ddl) 
     End If 
    End If 
End Sub 
+1

發佈您的'Page_Load'代碼。 –

回答

0

雖然結合下拉使用的IsPostBack選項。

if (!IsPostback) 
{ 
    BindDropdown1(); 
    BindDropdown2(); 
} 

這會保留你的狀態。如果在刷新頁面時每次下拉菜單都會被綁定,則不使用ispostback。因此,首次使用ispostback綁定下拉菜單。

+0

但只有一個ddls被綁定。你是說我需要爲綁定的ddl調用DataBind,並基於這個在IsPostBack和!IsPostBack情況下填充另一個ddl?我剛剛發佈了我的Page_Load代碼。你能指出我應該在那裏添加什麼?謝謝 – karineh

相關問題