Unigrid OnExternalDataBound's checkbox controls don't get refreshed after sorting

Ali Shahrokhi asked on February 23, 2016 01:37

Hi Kentico, There is a an issue with customized check-boxes in unigrid control as below:

when I use checkbox control within OnExternalDataBound function, everything is OK except when I click on any sort links, the value of check boxes remain the same!?

protected object unigridXXX_OnExternalDataBound(object sender, string sourceName, object parameter)
{
        var drv = (DataRowView)parameter;
        var obj = (DataControlFieldCell)sender;
        int reviewId = ValidationHelper.GetInteger(drv.Row["ItemID"], 0);
        bool isExcludedFromEmail = ValidationHelper.GetBoolean(drv.Row["EmailExclusion"], false);

        if (sourceName.ToLower() == "excludedemail")
        {
            CheckBox chkEmailExclusion = new CheckBox();
            chkEmailExclusion.Enabled = true;

            if (isAdmin || (isTrainingAdmin))
            {
                chkEmailExclusion.ID = "chkEmailExclusion";
                chkEmailExclusion.TextAlign = TextAlign.Left;
                chkEmailExclusion.Enabled = false;
                chkEmailExclusion.CssClass = "excluded-email";
                chkEmailExclusion.Checked = isExcludedFromEmail;
            }

            return chkEmailExclusion;
        }
}

Please let me know if this is a known bug and there is a workaround for that.

Current Kentico version: 8.2.16

Thanks,

Correct Answer

Ali Shahrokhi answered on February 24, 2016 02:15

I added the unique identifier to the check-box id and it fixed the problem as rocky suggested on SO website

chkEmailExclusion.ID = "chkEmailExclusion_" + reviewId ;
0 votesVote for this answer Unmark Correct answer

Recent Answers


Brian McKeiver answered on February 23, 2016 04:36

So does "When you click any sort links" mean clicking a column header of the grid to change the sortDirection? If so do you have any code like this to handle the OnDataReload event ?

//in Page_Load or similiar
...
ugMainGrid.OnDataReload += ugMainGrid_OnDataReload;
...

protected DataSet ugMainGrid_OnDataReload(string completeWhere, string currentOrder, int currentTopN, string columns, int currentOffset, int currentPageSize, ref int totalRecords)
    {
        DataSet ds = null;
        //.... do something to populate your dataset ....
        //.... order your dataset ....
        return ds;
    }
0 votesVote for this answer Mark as a Correct answer

Ali Shahrokhi answered on February 23, 2016 05:09 (last edited on February 23, 2016 05:26)

Yes, I do reload data on page load, as I stated in my question there is no problem with reloading data but just checkbox controls have this issue, even after I click on one of those column headers in order to sort and check the debug mode I can see the data are correctly assign to the check box controls, but the program still renders the old values on UI.

example: when I make a selection (e.g. the first three items) and then sort the grid, the first three items are still selected even though those are now no longer the three I chose before sorting.

also I should mention this the problem is only for checkbox control not label or button controls. I found that someone else has the same issue here but the problem was mainly for kentico default buiiltin checkbox not customized ones.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.