We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Dropdown List gets empty on Postback.

Thread ID:

Created:

Updated:

Platform:

Replies:

121710 Jan 19,2016 01:03 AM Jan 20,2016 12:28 AM ASP.NET Web Forms 1
loading
Tags: DropDownList
Gaurang
Asked On January 19, 2016 01:03 AM

Hi,

I am facing an issue where I am binding a datasource to dropdownlist from Access Database. 

Following works :

protected void Page_Load(object sender, EventArgs e)
        {
            
            ddlDepartment.DataSource = dtDept;
            ddlDepartment.DataBind();
        }

The above code binds the data to dropdownlist every time the page loads i.e on every postback.

But if i check the isPostback Property of Page and want to load the data only on the initial Page Load, the data gets lost after a postback event.

protected void Page_Load(object sender, EventArgs e)
        {
            if(!isPostBack)
           {
                 ddlDepartment.DataSource = dtDept;
                 ddlDepartment.DataBind();
             }
        }

Hence, unlike asp.net Dropdownlist, I cannot populate the Dropdown on first page load, I need to repopulate it on every page load and that has become an overhead. And this is the case with every other syncfusion control as well.. may it be Grid, Treeview, ListView, Accordian etc.

Please let me know if there is any work around for this. 

Thanks- 
Gaurang Kelkar

Ezhil S [Syncfusion]
Replied On January 20, 2016 12:28 AM

Hi Gaurang Kelkar,

Thank you for contacting Syncfusion support.

In order to maintain the DataSource bound after postback, we suggest you to use DataSourceCachingMode property with enum value ViewState or Session. This will maintain the data bound values in our controls after post back. Refer the following code sample,
<code>
[ASPX]

    <ej:DropDownList ID="DropDownList1" runat="server" DataTextField="text" DataValueField="value" DataSourceCachingMode="ViewState" >

      </ej:DropDownList>

       <br />
    <ej:TreeView ID="tree" runat="server" DataIdField="id" DataHasChildField="child" DataParentIdField="pid" DataTextField="name"DataSourceCachingMode="ViewState"></ej:TreeView>
</code>

Refer the following API reference: http://help.syncfusion.com/CR/cref_files/aspnet/ejweb/Syncfusion.EJ~Syncfusion.JavaScript.DataSourceCachingMode.html 
Sample link: http://www.syncfusion.com/downloads/support/directtrac/149809/ze/Dropdown_postback1226813838 

Please let us know if you have any other queries.

Regards,
Ezhil S



CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;