Hi everyone,
I am populating a dropdownlist based on the selection from another dorpdownlist. As long as there is no postback happening, I see the list getting populated correctly but after a postback, my dropdownlist is empty.
I am setting the DataValueField property of the ddl that I populate at runtime and the ViewStateMode for that ddl is set to Enabled.
Does anyone know what could be the reason?
JorgeM 958 Problem Solver Team Colleague Featured Poster
It would help to see your code. Its challenging to guess what is happening based on a description.
after a postback, my dropdownlist is empty.
Are you doing something to clear the dropdown at page_load? If you are building the drop down at page load, you may want to detect !IsPostBack so you only modify the drop down at first load and allow the viewstate to do its thing.
again, show your code so we can take a look.
Edited by JorgeM
geniusvishal -1 ~Coder~
May be you should check whether your dropdownlist is getting binded again on each postback..
If not then put the binding code inside the !page.ispostback section so that it will be binded on each postback.
Karineh_1 0 Newbie Poster
Thank you for your responses. I need to add one more piece of information. Both of these ddls are inside a Formview. I noticed that if I move the ddl that I populate programmatically (the one that loses its contents afte postback) outside of the Formview, then it retains its contents. The same thing happens with a textbox that resides inside the Formview. It is supposed to take user comments. In Insert mode, it loses its contents after postback but in Edit mode it retains. What is specific about Formviews?
Here is the code and thanks again for your comments.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles 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")
datasource_BuyerNVList.Dispose()
datasource_BuyerNVList.DataBind()
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
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.