Search code examples
asp.netsessiondevexpresscode-behindsqldatasource

ASPxCombobox not fetched from SQLdatasource saved in session


protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["SavedSQLSources"] == null)
                SavedSQLSources = new Dictionary<String, SqlDataSource>();

            SavedSQLSources.Add(ASPxComboBox1.ID, SqlDataSource1);
            SavedSQLSources.Add(ASPxComboBox2.ID, SqlDataSource2);

            Session["SavedSQLSources"] = SavedSQLSources;
        }
        else
        {
            if (Session["SavedSQLSources"] != null)
                SavedSQLSources = (Dictionary<String, SqlDataSource>)Session["SavedSQLSources"];
        }
    }

Greetings, I have multiple ASPxCombobox with each having their own datasource. So first I saved each control ID with their corresponding datasource object in a dictionary.

    protected void Cmb_Callback(object source, CallbackEventArgsBase e)
    {
        ASPxComboBox comboBox = (ASPxComboBox)source;
        string[] args = e.Parameter.Split('|');

        for (int i = 0; i < args.Length; ++i)
            SavedSQLSources[comboBox.ID].SelectParameters[i].DefaultValue = args[i];
        comboBox.DataSourceID = SavedSQLSources[comboBox.ID].ID;
        comboBox.DataBind();
    }

Doing a few actions on the page, each control then launch its callback and bind its data with the corresponding datasource.

Well... Work perfectly when using directly the datasource, but having no items fetched when it's from a datasource saved in Session (from SavedSQLSources). Shouldn't the instance of the object be the same ?

Thanks in advance, TheRainFall.


Solution

  • Ok, I gave up on the dictionnary method and resolved this by linking each ASPxCombobox to its SqlDatasource from client-side:

    DataSourceID="SqlDataSource1"
    

    Then in the callback I got the sqldatasource instance from the parent container by using the datasourceID referenced from client-side:

    SqlDataSource tempSqlDatasource= (SqlDataSource)comboBox.Parent.FindControl(comboBox.DataSourceID);
    

    The main purpose was to reload all combobox without reloading the page although I could have done this client-side only.