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"></ControlStyl e>
</asp:CommandField>
<asp:BoundField DataField="StudentName" HeaderText="Name" SortExpression="StudentNam e">
<ControlStyle Width="200px" />
<FooterStyle Width="320px" />
<HeaderStyle Width="320px" CssClass="PanelTitle" />
<ItemStyle Width="320px" />
</asp:BoundField>
<asp:TemplateField HeaderText="Assigned?" SortExpression="Interventi onCheckbox ">
<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="Interventi onDate">
<EditItemTemplate>
<asp:TextBox ID="txtInterventionDate" runat="server" Text='<%# Bind("InterventionDate") %>'></asp:TextBox>
<ajaxToolkit:CalendarExten der ID="txtInterventionDate_Ca lendarExte nder" runat="server" BehaviorID="txtInterventio nDate_Cale ndarExtend er" TargetControlID="txtInterv entionDate " />
</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="CompletedC heckBox">
<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="CompletedD ate">
<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 ([ChecklistAssignedRecordI d] = @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="ChecklistAssignedRec ordId" PropertyName="SelectedValu e" 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>
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
<Columns>
<asp:CommandField ShowEditButton="True" ControlStyle-Width="40px">
<ControlStyle Width="40px"></ControlStyl
</asp:CommandField>
<asp:BoundField DataField="StudentName" HeaderText="Name" SortExpression="StudentNam
<ControlStyle Width="200px" />
<FooterStyle Width="320px" />
<HeaderStyle Width="320px" CssClass="PanelTitle" />
<ItemStyle Width="320px" />
</asp:BoundField>
<asp:TemplateField HeaderText="Assigned?" SortExpression="Interventi
<EditItemTemplate>
<asp:CheckBox ID="ckbxAssigned" runat="server" Checked='<%# Bind("InterventionCheckbox
</EditItemTemplate>
<ItemTemplate>
<asp:CheckBox ID="ckbxAssigned" runat="server" Checked='<%# Bind("InterventionCheckbox
</ItemTemplate>
<ControlStyle Width="90px" />
<FooterStyle Width="90px" />
<HeaderStyle CssClass="PanelTitle" Width="90px" />
<ItemStyle Width="90px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Date" SortExpression="Interventi
<EditItemTemplate>
<asp:TextBox ID="txtInterventionDate" runat="server" Text='<%# Bind("InterventionDate") %>'></asp:TextBox>
<ajaxToolkit:CalendarExten
</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="CompletedC
<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="CompletedD
<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 ([ChecklistAssignedRecordI
UpdateCommand="UPDATE [Interventions] SET [StudentName] = @StudentName, [InterventionCheckBox] = @InterventionCheckBox, [InterventionDate] = @InterventionDate, [CompletedCheckBox] = @CompletedCheckBox, [CompletedDate] = @CompletedDate WHERE [InterventionRecordId] = @InterventionRecordId">
<DeleteParameters>
<asp:Parameter Name="InterventionRecordId
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="StudentName" Type="String" />
<asp:Parameter Name="InterventionCheckBox
<asp:Parameter DbType="DateTime2" Name="InterventionDate" />
<asp:Parameter Name="CompletedCheckBox" Type="Boolean" />
<asp:Parameter DbType="DateTime2" Name="CompletedDate" />
</InsertParameters>
<SelectParameters>
<asp:ControlParameter ControlID="ddlDateAndTitle
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="StudentName" Type="String" />
<asp:Parameter Name="InterventionCheckBox
<asp:Parameter DbType="DateTime2" Name="InterventionDate" />
<asp:Parameter Name="CompletedCheckBox" Type="Boolean" />
<asp:Parameter DbType="DateTime2" Name="CompletedDate" />
<asp:Parameter Name="InterventionRecordId
</UpdateParameters>
</asp:SqlDataSource>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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="Intervention RecordID" ?
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="Intervention
ASKER
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.
ASKER
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