jeudi 14 janvier 2016

NullReferenceException after a postback in a checkbox inside a devexpress gridview

I have the following code:

ASPX

<dx:ASPxGridView ID="gridSolicitudes"
                        runat="server"
                        AutoGenerateColumns="false"
                        EnableCallBacks="false"
                        EnableViewState="true"
                        OnCustomButtonCallback="GV_listadoSolicitudes_CustomButtonCallback"
                        OnCustomButtonInitialize="GV_listadoSolicitudes_CustomButtonInitialize"
                        Width="100%"
                        KeyFieldName="IdSolicitud"
                        CssClass="tableGrid"
                        SettingsPager-PageSize="20"
                        ClientInstanceName="gridSolicitudes"
                        Images-HeaderSortDown-Url="~/Responsive/images/portlet-arrow-down-icon.png"
                        Images-HeaderSortUp-Url="~/Responsive/images/portlet-arrow-up-icon.png">
                        <Columns>                                
                            <dx:GridViewDataTextColumn Width="2%"  FieldName="isSeleccionadaParaAutorizar">
                                <HeaderTemplate>
                                    <dx:ASPxCheckBox ID="cbCheckAll" runat="server">
                                    </dx:ASPxCheckBox>
                                </HeaderTemplate>
                                <DataItemTemplate>
                                    <dx:ASPxCheckBox ID="cbCheck" runat="server" Checked='<%# Eval("isSeleccionadaParaAutorizar") %>' Enabled='<%# Eval("isPendienteAutorizar") %>' AutoPostBack="true" OnCheckedChanged="cbCheck_CheckedChanged">
                                    </dx:ASPxCheckBox>                                       
                                </DataItemTemplate>
                            </dx:GridViewDataTextColumn>

As you can see, I have the checked and enable properties binded in a property from the entity binded in my gridview. Besides, I have OnCheckedChange cause I want to save the checkbox state. Now, when I click the checkbox, a nullReferenceException happens in Checked='<%# Eval("isSeleccionadaParaAutorizar") %>' cause Eval is returning a null, so it seems the entity has not been binded correctly.

I tried to change the code with a <%#Convert.ToBoolean(Eval('... and then the problem is solved, but the event doesn't fire and my gridview shows practically no info (just the first row completely and two or three columns of the other rows), besides, all checkbox are disabled (I guess because convert.toboolean returns a false when it tries to convert a null value).

For aditional info I put my databind inside a !Page.IsPostBack and again inside the checkedchange event.

What is happening?

Thanks




Aucun commentaire:

Enregistrer un commentaire