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. Image for the cookie policy date

Dropdown List gets empty on Postback.

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

1 Reply

ES Ezhil S Syncfusion Team January 20, 2016 05:28 AM UTC

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



Loader.
Up arrow icon