Link to home
Start Free TrialLog in
Avatar of bobbellows
bobbellows

asked on

My Gridview won't update. What am I missing?

Dear Experts,
I've looked and looked at this markup/code and can't figure out why when I click "Update" on the gridview the page posts back as if the update occurred but no changes show up neither in the Gridview nor in the database. Can you find what I'm missing?
Thanks.

<asp:GridView ID="gvChecklist" runat="server" AutoGenerateColumns="False" DataSourceID="sdsChecklist" Style="text-align: center">
                    <Columns>
                        <asp:CommandField ShowEditButton="True" ControlStyle-Width="40px">
                            <ControlStyle Width="40px"></ControlStyle>
                        </asp:CommandField>
                        <asp:BoundField DataField="StudentName" HeaderText="Name" SortExpression="StudentName">
                            <ControlStyle Width="200px" />
                            <FooterStyle Width="320px" />
                            <HeaderStyle Width="320px" CssClass="PanelTitle" />
                            <ItemStyle Width="320px" />
                        </asp:BoundField>
                        <asp:TemplateField HeaderText="Assigned?" SortExpression="InterventionCheckbox">
                            <EditItemTemplate>
                                <asp:CheckBox ID="ckbxAssigned" runat="server" Checked='<%# Bind("InterventionCheckbox") %>' />
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:CheckBox ID="ckbxAssigned" runat="server" Checked='<%# Bind("InterventionCheckbox") %>' Enabled="false" />
                            </ItemTemplate>
                            <ControlStyle Width="90px" />
                            <FooterStyle Width="90px" />
                            <HeaderStyle CssClass="PanelTitle" Width="90px" />
                            <ItemStyle Width="90px" />
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Date" SortExpression="InterventionDate">
                            <EditItemTemplate>
                                <asp:TextBox ID="txtInterventionDate" runat="server" Text='<%# Bind("InterventionDate") %>'></asp:TextBox>
                                <ajaxToolkit:CalendarExtender ID="txtInterventionDate_CalendarExtender" runat="server" BehaviorID="txtInterventionDate_CalendarExtender" TargetControlID="txtInterventionDate" />
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="Label1" runat="server" Text='<%# Bind("InterventionDate", "{0:d}") %>'></asp:Label>
                            </ItemTemplate>
                            <ControlStyle Width="90px" />
                            <FooterStyle Width="90px" />
                            <HeaderStyle CssClass="PanelTitle" Width="90px" />
                            <ItemStyle Width="90px" />
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Completed?" SortExpression="CompletedCheckBox">
                            <EditItemTemplate>
                                <asp:CheckBox ID="ckbxCompleted" runat="server" Checked='<%# Bind("CompletedCheckBox") %>' />
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:CheckBox ID="ckbxCompleted" runat="server" Checked='<%# Bind("CompletedCheckBox") %>' Enabled="false" />
                            </ItemTemplate>
                            <ControlStyle Width="90px" />
                            <FooterStyle Width="90px" />
                            <HeaderStyle CssClass="PanelTitle" Width="90px" />
                            <ItemStyle Width="90px" />
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Date" SortExpression="CompletedDate">
                            <EditItemTemplate>
                                <asp:TextBox ID="txtCompletedDate" runat="server" Text='<%# Bind("CompletedDate") %>'></asp:TextBox>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="Label2" runat="server" Text='<%# Bind("CompletedDate", "{0:d}") %>'></asp:Label>
                            </ItemTemplate>
                            <ControlStyle Width="90px" />
                            <FooterStyle Width="90px" />
                            <HeaderStyle CssClass="PanelTitle" Width="90px" />
                            <ItemStyle Width="90px" />
                        </asp:TemplateField>
                    </Columns>
                </asp:GridView>

      <asp:SqlDataSource ID="sdsChecklist" runat="server" ConnectionString="<%$ ConnectionStrings:ICSS %>"
          DeleteCommand="DELETE FROM [Interventions] WHERE [InterventionRecordId] = @InterventionRecordId"
          InsertCommand="INSERT INTO [Interventions] ([StudentName], [InterventionCheckBox], [InterventionDate], [CompletedCheckBox], [CompletedDate]) VALUES (@StudentName, @InterventionCheckBox, @InterventionDate, @CompletedCheckBox, @CompletedDate)"
          SelectCommand="SELECT [InterventionRecordId], [StudentName], [InterventionCheckBox], [InterventionDate], [CompletedCheckBox], [CompletedDate] FROM [Interventions] WHERE ([ChecklistAssignedRecordId] = @ChecklistAssignedRecordId)"
          UpdateCommand="UPDATE [Interventions] SET [StudentName] = @StudentName, [InterventionCheckBox] = @InterventionCheckBox, [InterventionDate] = @InterventionDate, [CompletedCheckBox] = @CompletedCheckBox, [CompletedDate] = @CompletedDate WHERE [InterventionRecordId] = @InterventionRecordId">
          <DeleteParameters>
              <asp:Parameter Name="InterventionRecordId" Type="Int32" />
          </DeleteParameters>
          <InsertParameters>
              <asp:Parameter Name="StudentName" Type="String" />
              <asp:Parameter Name="InterventionCheckBox" Type="Boolean" />
              <asp:Parameter DbType="DateTime2" Name="InterventionDate" />
              <asp:Parameter Name="CompletedCheckBox" Type="Boolean" />
              <asp:Parameter DbType="DateTime2" Name="CompletedDate" />
          </InsertParameters>
          <SelectParameters>
              <asp:ControlParameter ControlID="ddlDateAndTitle" Name="ChecklistAssignedRecordId" PropertyName="SelectedValue" Type="Int32" />
          </SelectParameters>
          <UpdateParameters>
              <asp:Parameter Name="StudentName" Type="String" />
              <asp:Parameter Name="InterventionCheckBox" Type="Boolean" />
              <asp:Parameter DbType="DateTime2" Name="InterventionDate" />
              <asp:Parameter Name="CompletedCheckBox" Type="Boolean" />
              <asp:Parameter DbType="DateTime2" Name="CompletedDate" />
              <asp:Parameter Name="InterventionRecordId" Type="Int32" />
          </UpdateParameters>
      </asp:SqlDataSource>
ASKER CERTIFIED SOLUTION
Avatar of Easwaran Paramasivam
Easwaran Paramasivam
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bobbellows
bobbellows

ASKER

Easwaran,
Delete not activated -- even though the controller has the commands -- Records too critical for user to delete. I'm not sure what you mean "the profiler." Even though I've been working with asp.net for some time I've never used gridview till this week.
BB
Well. Go to SSMS > Tools > Profiler > Give the database details as same as connection string and start.
Perform update in Gridview. The Update command should be hit in the profiler. For more information please look at http://www.codeproject.com/Articles/21371/SQL-Server-Profiler-Step-by-Step

BTW did you try by adding the DataKeyNames="InterventionRecordID" ?
Didn't need to run the profiler. Easwaran nailed it when he saw I didn't have the DataKeyNames. Added DataKeyNames to the properties of the Gridview and on the next trial it made the changes. Thanks.