mercredi 21 décembre 2016

checkbox itemtemplate not updating into an ASP GridView

working on an ASP Gridview querying a SQL server base.

<asp:Content ID="i_cttContenu" runat="server" ContentPlaceHolderID="i_cphContenu">
    <asp:SqlDataSource ID="i_sdsGvOption" runat="server" ConnectionString="<%$ ConnectionStrings:... %>"
        SelectCommand=" SELECT *    FROM MyTable " SelectCommandType="Text"      
        UpdateCommand="UPDATE MyTable   SET [name] = @name, prenom = @prenom, isAlive = @isAlive WHERE idWsgProgramOption = @idWsgProgramOption" UpdateCommandType="Text" 
    </asp:SqlDataSource>

    <asp:UpdatePanel ID="i_up" runat="server">
        <ContentTemplate>
            <asp:GridView ID="i_gvOption" runat="server" AutoGenerateColumns="False" DataKeyNames="idWsgProgramOption"
                DataSourceID="i_sdsGvOption" EnableModelValidation="True">

                <Columns>
                    <asp:CommandField ButtonType="Image" CancelImageUrl="~/....gif"
                        CancelText="Annuler" EditImageUrl="~/....gif" 
                        EditText="Update" HeaderText="M"  UpdateImageUrl="~/....gif"
                        UpdateText="Save">
                    </asp:CommandField>


                    <asp:TemplateField HeaderText="Nom" SortExpression="name">
                        <ItemTemplate>
                            <asp:HyperLink ID="i_hlOption" runat="server" NavigateUrl='<%# Eval("idWsgProgramOption", "~/myURL") %>'
                                Text='<%# Eval("name") %>' />
                        </ItemTemplate>
                        <EditItemTemplate>
                            <table >
                                <tr>
                                    <td >
                                        <asp:TextBox ID="i_tbNom" runat="server" Text='<%# Bind("name") %>' />
                                    </td>
                                </tr>
                            </table>
                        </EditItemTemplate>
                    </asp:TemplateField>




                      <asp:TemplateField HeaderText="prenom" SortExpression="prenom">
                        <ItemTemplate>
                            <asp:HyperLink ID="i_hlprenom" runat="server" NavigateUrl='<%# Eval("prenom", "~/myURL") %>'
                                Text='<%# Eval("prenom") %>' />
                        </ItemTemplate>
                        <EditItemTemplate>
                            <table >
                                <tr>
                                    <td >
                                        <asp:TextBox ID="i_tbprenom" runat="server" Text='<%# Bind("prenom") %>' />
                                    </td>
                                </tr>
                            </table>
                        </EditItemTemplate>
                    </asp:TemplateField>



         <asp:TemplateField HeaderText="Obligatoire" >
                    <ItemTemplate>
                        <asp:CheckBox ID="CB_id1" runat="server"   />
                    </ItemTemplate>   
                     <EditItemTemplate>
                          <asp:CheckBox ID="CB_id2" runat="server"  />
                         </EditItemTemplate>                   
                </asp:TemplateField>


                </Columns>

            </asp:GridView>



        </ContentTemplate>        


    </asp:UpdatePanel>
</asp:Content>

The update() method is not invoked when I click the update button (first column). If I add an onUpdating event into the datasource, the corresponding method is never invoked.

The code causing the issue is definitely the checkbox. If I remove from the datasource update query: , isAlive = @isAlive and only set:

UPDATE MyTable   SET [name] = @name, prenom = @prenom, isAlive = @isAlive WHERE idWsgProgramOption = @idWsgProgramOption;

Then it updates fine (except the isAlive field of course). I am 100% sure that the isAlive field exists into the base (bit type).

So it looks that my problem comes from this bloc:

  <asp:TemplateField HeaderText="Obligatoire" >
                    <ItemTemplate>
                        <asp:CheckBox ID="CB_id1" runat="server"   />
                    </ItemTemplate>   
                     <EditItemTemplate>
                          <asp:CheckBox ID="CB_id2" runat="server"  />
                         </EditItemTemplate>                   
                </asp:TemplateField>

Is there anything obvious that I missed??

Also, this is the simplified code, but if I set the "checked" property to the checkbox and correctly binds, the rows checkbox is correctly field. So the issue does not affect the select but only the update.




Aucun commentaire:

Enregistrer un commentaire