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.
spacecenterhoustonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

plusone3055Commented:
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
0
Kyle AbrahamsSenior .Net DeveloperCommented:
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>
0
spacecenterhoustonAuthor Commented:
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>
0
Lokesh B RDeveloperCommented:
Hi,

1. GridView doesn't have AutoPostBack property.

2. After the record deleted, You need to Update the Count in below event.

a) Add the event to GridView

        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="lngKeyRooms" DataSourceID="AccessDataSource1" OnRowDeleted="GridView1_RowDeleted">

b) Update the Values

Protected Sub GridView1_RowDeleted(sender As Object, e As GridViewDeletedEventArgs)
	GridView1.DataBind()
	lblTotalRooms.Text = GridView1.Rows.Count.ToString()
	' You need to Update the valeus here once deleted
	txtRoom.Text = GridView1.Rows.Count.ToString()
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
spacecenterhoustonAuthor Commented:
Worked perfect.  Thanks so much.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.