Larry Angermiller
asked on
refresh webpage after gridview delete
Have a gridview on an asp.net (aspx) page. On the same webpage is another control (texbox) that needs to be updated when the gridview is updated, specifically when a record is deleted. I don't know where to put a page reload. If I put it in the aspx.vb page, then the delete does not occur. The control on the gridview for the delete is a template field. The delete works fine, i just can't figure out how to refresh the page after the delete.
Thanks.
Thanks.
Are the text box and gridview next to each other? If so you can wrap them in an update panel and use the autopostback as described:
<asp:UpdatePanel runat ="server" id="upGridView">
<ContentTemplate>
... gridview & Textbox
</ContentTemplate>
</UpdatePanel>
<asp:UpdatePanel runat ="server" id="upGridView">
<ContentTemplate>
... gridview & Textbox
</ContentTemplate>
</UpdatePanel>
ASKER
The autopostback=true did not do the update. And if i put the redirect in the delete event it does not process the delete. That i don't understand. It looks like it does the refresh before the delete as it will update the textbox before the delete so if i do a delete it is like one behind. I have 4 records, delete 1 record, textbox still says 4 records. i do a 2nd delete, to 2 records, textbox says 3.
I want to try the update panel but now sure with what i have where to put. Have included the page html if you can direct me how to use.
the textbox 'txtRoom' and gridview1 are the two items i am working with. When i delete an item from the gridview i need to refresh the textbox also.
Thanks for the help. Larry
<tr>
<td class="style1">
</td>
<td>
<asp:TextBox ID="txtRoom" runat="server" Width="114px"></asp:TextBo x>
</td>
<td>
</td>
</tr>
<tr>
<td align="right" class="style1">
</td>
<td>
<asp:Label ID="Label1" runat="server" Text="Total rooms:"></asp:Label>
<asp:Label ID="lblTotalRooms" runat="server" Text="0"></asp:Label>
</td>
<td>
</td>
</tr>
<tr>
<td class="style1">
</td>
<td>
<asp:Button ID="Button1" runat="server" Text="Add Room" />
</td>
<td>
</td>
</tr>
<tr>
<td class="style1">
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td class="style1">
</td>
<td>
<asp:GridView ID="GridView1" runat="server" AutoPostBack="True" AutoGenerateColumns="False "
DataKeyNames="lngKeyRooms" DataSourceID="AccessDataSo urce1">
<Columns>
<asp:CommandField ShowSelectButton="True" ShowDeleteButton="True"
SelectText="Edit Room Occupants" />
<asp:BoundField DataField="lngKeyRooms" HeaderText="lngKeyRooms"
InsertVisible="False" ReadOnly="True" SortExpression="lngKeyRoom s" />
<asp:BoundField DataField="intRoom" HeaderText="intRoom"
SortExpression="intRoom" />
<asp:BoundField DataField="intTotalOccupan ts" HeaderText="intTotalOccupa nts"
SortExpression="intTotalOc cupants" />
<asp:BoundField DataField="lngGroup" HeaderText="lngGroup"
SortExpression="lngGroup" />
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False"
CommandName="Delete" Text="Delete Room"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/App_Data/Space U.mdb"
SelectCommand="SELECT * FROM [tblRooms] WHERE ([lngGroup] = ?) ORDER BY [intRoom]"
DeleteCommand="DELETE FROM [tblRooms] WHERE [lngKeyRooms] = ?"
InsertCommand="INSERT INTO [tblRooms] ([lngKeyRooms], [intTotalOccupants], [lngGroup], [intRoom]) VALUES (?, ?, ?, ?)"
UpdateCommand="UPDATE [tblRooms] SET [intTotalOccupants] = ?, [lngGroup] = ?, [intRoom] = ? WHERE [lngKeyRooms] = ?">
<DeleteParameters>
<asp:Parameter Name="lngKeyRooms" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="lngKeyRooms" Type="Int32" />
<asp:Parameter Name="intTotalOccupants" Type="Int16" />
<asp:Parameter Name="lngGroup" Type="Int32" />
<asp:Parameter Name="intRoom" Type="Int16" />
</InsertParameters>
<SelectParameters>
<asp:SessionParameter Name="lngGroup" SessionField="GroupKey" Type="Int32" />
</SelectParameters>
I want to try the update panel but now sure with what i have where to put. Have included the page html if you can direct me how to use.
the textbox 'txtRoom' and gridview1 are the two items i am working with. When i delete an item from the gridview i need to refresh the textbox also.
Thanks for the help. Larry
<tr>
<td class="style1">
</td>
<td>
<asp:TextBox ID="txtRoom" runat="server" Width="114px"></asp:TextBo
</td>
<td>
</td>
</tr>
<tr>
<td align="right" class="style1">
</td>
<td>
<asp:Label ID="Label1" runat="server" Text="Total rooms:"></asp:Label>
<asp:Label ID="lblTotalRooms" runat="server" Text="0"></asp:Label>
</td>
<td>
</td>
</tr>
<tr>
<td class="style1">
</td>
<td>
<asp:Button ID="Button1" runat="server" Text="Add Room" />
</td>
<td>
</td>
</tr>
<tr>
<td class="style1">
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td class="style1">
</td>
<td>
<asp:GridView ID="GridView1" runat="server" AutoPostBack="True" AutoGenerateColumns="False
DataKeyNames="lngKeyRooms"
<Columns>
<asp:CommandField ShowSelectButton="True" ShowDeleteButton="True"
SelectText="Edit Room Occupants" />
<asp:BoundField DataField="lngKeyRooms" HeaderText="lngKeyRooms"
InsertVisible="False" ReadOnly="True" SortExpression="lngKeyRoom
<asp:BoundField DataField="intRoom" HeaderText="intRoom"
SortExpression="intRoom" />
<asp:BoundField DataField="intTotalOccupan
SortExpression="intTotalOc
<asp:BoundField DataField="lngGroup" HeaderText="lngGroup"
SortExpression="lngGroup" />
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False"
CommandName="Delete" Text="Delete Room"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/App_Data/Space
SelectCommand="SELECT * FROM [tblRooms] WHERE ([lngGroup] = ?) ORDER BY [intRoom]"
DeleteCommand="DELETE FROM [tblRooms] WHERE [lngKeyRooms] = ?"
InsertCommand="INSERT INTO [tblRooms] ([lngKeyRooms], [intTotalOccupants], [lngGroup], [intRoom]) VALUES (?, ?, ?, ?)"
UpdateCommand="UPDATE [tblRooms] SET [intTotalOccupants] = ?, [lngGroup] = ?, [intRoom] = ? WHERE [lngKeyRooms] = ?">
<DeleteParameters>
<asp:Parameter Name="lngKeyRooms" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="lngKeyRooms" Type="Int32" />
<asp:Parameter Name="intTotalOccupants" Type="Int16" />
<asp:Parameter Name="lngGroup" Type="Int32" />
<asp:Parameter Name="intRoom" Type="Int16" />
</InsertParameters>
<SelectParameters>
<asp:SessionParameter Name="lngGroup" SessionField="GroupKey" Type="Int32" />
</SelectParameters>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Worked perfect. Thanks so much.
the other simple option is to Response.Redirect(Request.