Link to home
Start Free TrialLog in
Avatar of Larry Angermiller
Larry AngermillerFlag for United States of America

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.
Avatar of plusone3055
plusone3055
Flag of United States of America image

Have you tried an  autopostback=true  after the delete ?

the other simple option is to Response.Redirect(Request.URL.ToString()) on your delete event as well
Avatar of Kyle Abrahams, PMP
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>
Avatar of Larry Angermiller

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">
                    &nbsp;</td>
                <td>
                    <asp:TextBox ID="txtRoom" runat="server" Width="114px"></asp:TextBox>
                </td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td align="right" class="style1">
                    &nbsp;</td>
                <td>
                    <asp:Label ID="Label1" runat="server" Text="Total rooms:"></asp:Label>
                &nbsp;&nbsp;
                    <asp:Label ID="lblTotalRooms" runat="server" Text="0"></asp:Label>
                </td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td class="style1">
                    &nbsp;</td>
                <td>
                    <asp:Button ID="Button1" runat="server" Text="Add Room" />
                </td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td class="style1">
                    &nbsp;</td>
                <td>
                    &nbsp;</td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td class="style1">
                    &nbsp;</td>
                <td>
                    <asp:GridView ID="GridView1" runat="server" AutoPostBack="True" AutoGenerateColumns="False"
                        DataKeyNames="lngKeyRooms" DataSourceID="AccessDataSource1">
                        <Columns>
                            <asp:CommandField ShowSelectButton="True" ShowDeleteButton="True"
                                SelectText="Edit Room Occupants"  />
                            <asp:BoundField DataField="lngKeyRooms" HeaderText="lngKeyRooms"
                                InsertVisible="False" ReadOnly="True" SortExpression="lngKeyRooms" />
                            <asp:BoundField DataField="intRoom" HeaderText="intRoom"
                                SortExpression="intRoom" />
                            <asp:BoundField DataField="intTotalOccupants" HeaderText="intTotalOccupants"
                                SortExpression="intTotalOccupants" />
                            <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/SpaceU.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>
ASKER CERTIFIED SOLUTION
Avatar of Lokesh B R
Lokesh B R
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
Worked perfect.  Thanks so much.