GridView is not Refreshing after deleting record. How do i make it refresh.

I created a page where i have GridView and a DetailView.  The DetailView is filled using the GridViews key as parameter.  But after I finish doing any update nither the GridView nor the DetailView refreshes the changes.  What am I missing?

 

Thanks for any suggestions?

0
mendez_edd
1/12/2006 2:04:28 PM
asp.net.getting-started 91979 articles. 3 followers. Follow

5 Replies
692 Views

Similar Articles

[PageSpeed] 15

First, verify that your database doesnt actually still contain the record your trying to delete.  It's very common to assume that the record was deleted, when in fact it still exists.

Second, check caching, if your doing web caching, your not going to be hitting the database each time the page reloads.  Which means, until the cache refreshes, your not going to see that the record was deleted.

 


Bryan Sampica
Auction Site StarterKit |
My Blog
0
Freakyuno
1/12/2006 3:44:33 PM

Thanks a lot for your answer,

 

But I still do not get the SqlDataSource1 to refresh the GridView.  The cache duration is set to Infinite and the CacheExpirationPolicy is set to absolute.

The DetailView (Wich used SqlDataSource2) is doing its job, becase It updates the database.  And if I close and load again the changes take effect.

I am going to copy/paste the code just if you want to take a look at it.

Thanks

 

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Agencias.aspx.vb" Inherits="Agencias" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

<title>Untitled Page</title>

</head>

<body bottommargin="5">

<form id="form1" runat="server">

<div align="center">

<asp:SqlDataSource ID="SqlDataSourceAgencias" runat="server" ConnectionString="<%$ ConnectionStrings:Registro_ExpedienteConnectionString %>"

SelectCommand="SELECT [Siglas], [Nombre_agencia] FROM [tblAgencias] ORDER BY [Siglas], [Nombre_agencia]" DeleteCommand="DELETE FROM [tblAgencias] WHERE [Siglas] = @Siglas" InsertCommand="INSERT INTO [tblAgencias] ([Siglas], [Nombre_agencia]) VALUES (@Siglas, @Nombre_agencia)" UpdateCommand="UPDATE [tblAgencias] SET [Nombre_agencia] = @Nombre_agencia WHERE [Siglas] = @Siglas">

<DeleteParameters>

<asp:Parameter Name="Siglas" Type="String" />

</DeleteParameters>

<UpdateParameters>

<asp:Parameter Name="Nombre_agencia" Type="String" />

<asp:Parameter Name="Siglas" Type="String" />

</UpdateParameters>

<InsertParameters>

<asp:Parameter Name="Siglas" Type="String" />

<asp:Parameter Name="Nombre_agencia" Type="String" />

</InsertParameters>

</asp:SqlDataSource>

<br />

<asp:Label ID="lblErrorMessage" runat="server" ForeColor="#FF8080" Style="position: relative"></asp:Label><br />

<strong style="font-size: 30pt">AGENCIAS</strong><br />

<br />

<br />

</div>

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"

AutoGenerateColumns="False" CellPadding="4" DataKeyNames="Siglas" DataSourceID="SqlDataSourceAgencias"

GridLines="None" HorizontalAlign="Center" Style="position: relative; left: -14px; top: -14px;" Width="741px" ForeColor="#333333">

<FooterStyle BackColor="#1C5E55" ForeColor="White" Font-Bold="True" />

<Columns>

<asp:CommandField

ShowSelectButton="True" />

<asp:BoundField DataField="Siglas" HeaderText="Siglas" ReadOnly="True" SortExpression="Siglas" />

<asp:BoundField DataField="Nombre_agencia" HeaderText="Agencia" SortExpression="Nombre_agencia" />

</Columns>

<RowStyle BackColor="#E3EAEB" />

<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />

<PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />

<HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />

<AlternatingRowStyle BackColor="White" />

<EditRowStyle BackColor="#7C6F57" />

</asp:GridView>

&nbsp;

<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataKeyNames="Siglas"

DataSourceID="SqlDataSourceAgenciaDetalles" Height="50px" HorizontalAlign="Center"

Style="left: 0px; position: relative; top: 45px" Width="612px" AllowPaging="True">

<Fields>

<asp:BoundField DataField="Siglas" HeaderText="Siglas" ReadOnly="True" SortExpression="Siglas" />

<asp:BoundField DataField="Nombre_agencia" HeaderText="Agencia" SortExpression="Nombre_agencia" />

<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ShowInsertButton="True" />

</Fields>

</asp:DetailsView>

&nbsp;&nbsp;

<asp:SqlDataSource ID="SqlDataSourceAgenciaDetalles" runat="server" ConnectionString="<%$ ConnectionStrings:Registro_ExpedienteConnectionString %>"

DeleteCommand="DELETE FROM [tblAgencias] WHERE [Siglas] = @Siglas" InsertCommand="INSERT INTO [tblAgencias] ([Siglas], [Nombre_agencia]) VALUES (@Siglas, @Nombre_agencia)"

SelectCommand="SELECT [Siglas], [Nombre_agencia] FROM [tblAgencias] WHERE ([Siglas] = @Siglas)" UpdateCommand="UPDATE [tblAgencias] SET [Nombre_agencia] = @Nombre_agencia WHERE [Siglas] = @Siglas">

<DeleteParameters>

<asp:Parameter Name="Siglas" Type="String" />

</DeleteParameters>

<UpdateParameters>

<asp:Parameter Name="Nombre_agencia" Type="String" />

<asp:Parameter Name="Siglas" Type="String" />

</UpdateParameters>

<SelectParameters>

<asp:ControlParameter ControlID="GridView1" Name="Siglas" PropertyName="SelectedValue"

Type="String" />

</SelectParameters>

<InsertParameters>

<asp:Parameter Name="Siglas" Type="String" />

<asp:Parameter Name="Nombre_agencia" Type="String" />

</InsertParameters>

</asp:SqlDataSource>

</form>

</body>

</html>

 

0
mendez_edd
1/12/2006 5:30:58 PM

I would think you'd still need a subroutine to handle that, with the code:

Sub DVAfterDelete(sender As Object, e As DetailsViewDeleteEventArgs)
GridView1.DataBind
End Sub

Then, in the DetailsView:
OnItemDeleted="DVAfterDelete"

Naturally, it would change to OnItemUpdated and DetailsViewUpdateEventArgs, when you are doing an Update/Edit


David Wier
MCP/ASPInsider
ASPNet101.com - where to look first!
Please Vote for ASPNet101 - 'Best Community Resource'!
Control Grouper - easily control properties for multiple controls with one control!
Calendar Express - The Best HTML Calendar Generator on the web!
(Please 'Mark as Answer' when it applies)
0
augustwind
1/12/2006 6:05:44 PM

Thanks for your time,

 

I did just what you told me but it is asking for a parameter when calling the DVAfterDelete.

 

This is what i have:

 

Protected Sub DetailsView1_ItemDeleted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewDeletedEventArgs) Handles DetailsView1.ItemDeleted

 

DeAfterDelete()

End Sub

 

Public Sub DVAfterDelete(ByVal sender As Object, ByVal e As DetailsViewDeleteEventArgs)

Me.GridView1.DataBind()

End Sub

0
mendez_edd
1/12/2006 6:17:17 PM

You just need one of the subs for what you were originally asking - -

Just add : Me.GridView1.DataBind() 

to the top sub - and delete the second other line, and the second sub


David Wier
MCP/ASPInsider
ASPNet101.com - where to look first!
Please Vote for ASPNet101 - 'Best Community Resource'!
Control Grouper - easily control properties for multiple controls with one control!
Calendar Express - The Best HTML Calendar Generator on the web!
(Please 'Mark as Answer' when it applies)
0
augustwind
1/12/2006 8:55:54 PM
Reply:

Similar Artilces:

Page is not getting refreshed but my datagrid is getting refreshed how to refresh the page
Hi EveryOne, Im getting a problem here that my datgrid is getting refreshed for every Updation ,Edit,Cancel commands but the page is not getting refreshed so anybody can help me how a page gets refreshed in a button click in C# of Asp.Net.                            Thanx in Advance RuttsRatnakar Choudry,c.ratnakar@gmail.com,Tension Nahi Leneka Apun Hai Nah... When you do an update on the DataGrid, for sure a postback happens! So how is it that the DataG...

Refresh does not refresh
Name: Udo Steinbach Email: usenetatudolinedotde Product: Firefox Summary: Refresh does not refresh Comments: I had build some SVG and inserted them with <a href="xxx.html"><object data="xxx.svg" type="image/svg+xml" style="..."><img src="xxx.png" style="..."/></object> other text</a> in one file, several graphics every multiple times. Firefox showed the page correct. Because I forgot a point to insert a graphic I edited the file again, and then pressed F5 (refresh) in Firefox to display ...

IE refresh button delete Gridview record.
Hi,all:our web application using vb.net and xp. we have a web form using aGridview, when load that page, it will list all our cutomer info. to theGridview. The first column of the Gridview is "delete button" which bind withCustomerID, when we click delete button the record will be delete properly.But I found that if we us IE refresh icon to refresh the page, we got IE popup message: "The page cannot be refreshed without resending the infomation.Click Retry to send the information again, or click Cancel to return to thepage that you were trying to view." if I click Retry button, the page will...

GridView RowDeleting delets record on per refresh
Hi, I am using a gridview and setting datatable as its datasorce. I am also generating the delete link and set datakeynames. But problem is when RowDeleting event fires. It delets that specific row but if I refresh the page, it delets follwing subsequent rows. Here is the codeDim dt As DataTable dt = Session("DT")Dim Id As String = GridView1.DataKeys(e.RowIndex).Value.ToString Dim allRows As DataRowCollection = dt.RowsDim delRow As DataRow = allRows.Find(Id) If Not IsNothing(delRow) Then allRows.Remove(delRow)Session("DT") = dt GridView1.DataSource = dt G...

Gridview Refresh or Page refresh
Hello I have a Gridview with user information i am writing the code to change the color when the checkbox is clicked.. Same like if you see or Gmail(Inbox items) but here what happing is when i click one row the whole page is refreshing back..I dont wnat to refresh the whole page.. Just the page should be constant and I need to change the Color of the row.. how it is possible any ideas.protected void Checkbox1_CheckedChanged(object sender, EventArgs e) { CheckBox chk = (CheckBox)sender;GridViewRow gvr = (GridViewRow)chk.NamingContainer;if (chk.Checked) {gvr.BackColor = System.Drawing...

GridView inserting or deleting records on page refresh problem.?
Hi I have a gridview and a formview. From my formview I insert record to Sqldatasource and show it on the gridview. I also have delete button on my gridview. Which works fine. But When A user refreshes the page the last action repeats itself. For example if I inserted a record, it inserts the same record again, or if i deleted o row, it deletes next row. How could I disable that? So when user refresh the page, last action will not repeat. Any help would greatly appreciated. Hi, You have a few options. You can try database before each insert, update or delete command, and t...

Getting data without refreshing the page
Hi I want to be able to retrieve some data from a database when an object is clicked on the web page, but I don't want to refresh the page.  When I used to use ASP I would use a hidden IFRAME (to do a hidden post) or even RDS (if I felt brave!).  However, I have seen some .net sites that seem to handle this in a far more graceful way. Not sure if the answer is actually AJAX and not through a .NET.   You can use the AJAX.NET framework or you use your own javascript libaries but it is done through javascript calls.Matthew M. Osbornhttp://blog.osbornm.comhttp://webl...

what is the Difference between page refresh and gridview refresh
I am just testing if i have a shared datatable binded to a grid then should the change in datatable be reflected.I have open a page on its one button click event i have binded it to the data table.Then I open another browser on one of it's button click event i updated the datatable.Then in the previous browser 1, if i just refresh page i manage to see the new data.2, if i just refresh the grid i can't see the changes also after refreshing the data if i refresh the page i still can't see the changes.Kamran ShahidSr. Software Engineer(MCP,MCAD.net,MCSD.net,MCTS,MCPD.net[web])Netprosys Inc.www....

How to get gridview to refresh
I have a dropdownlist (set to autopostback), in the SelectedIndexChanged event I am calling a bit of code :        SDS_Projects.SelectCommand = somethingDifferent;        SDS_Projects.DataBind();        SDS_Projects.Select(DataSourceSelectArguments.Empty); I am changing the select string in this event, and the screen redraws, but the grid does not update.  Where is this event called?  Is it called AFTER the page_load event?  How do I force the grid to redisplay? Cal...

Refresh gridview after delete.
 Hi,  I'm having a problem with refreshing my UpdatePanel.  Once I bind my gridview, I see the the right data is there.Then I try Updating my UpdatePanel and nothing happens.It is set to conditional... Here's the code:  gvHelpRequests.DataSource = iTeamPlanningID; gvHelpRequests.DataBind(); this.upHelpRequests.Update();   Any idea why this doesn't work?   Y you want to refresh the Update Panel again..??SSNPlease remember to click "Mark as Answer" on the post that helps you. A&nb...

Refresh GridView after delete
I have a GridView that is populated by data from an SQL database. There is a delete button on the GridView that allows users to delete rows of data.Is there anyway to automatically refresh this GridView with the updated database information after the deletion without having to re-submit the original query to the dB? Normally I would just run another SELECT statement to populate the GridView with the updated data, but it's a bit more complex this time as the SELECT statement is determined by user input, so it's not always going to be the same. E.g. The user will search for...

Delete in GridView using OnClick method not Refreshing GridView Control
Hi, I have added a GridView control to my Personal Site and am using it to edit the content of the site, which I am storing in an MS Access database. The content is stored in a table called SiteContent with 4 columns: ContentCode, ContentLineNo, ContentElementType and ContentText. Without any code, the Delete LinkButton of the GridView was happily deleting rows from the table and refreshing immediately to show the change. However, I wanted the Delete LinkButton to also reduce the ContentLineNo column of each following row by 1, so I removed its CommandName="Delete" attribute and substitute...

Any Way to Get UpdatePanel to Refresh Programatically DURING a Refresh?
The subject line may sound strange.  Let me explain.  No, it's too much--let me sum up. I have a user control that builds a series of server controls dynamically (text boxes, dropdown lists, etc.).  Because some of these dynamic controls have to respond to events, I have to do all this wiring in the OnInit event of the control.  This actually all works very well on its own. What I'd like to do is have an updatepanel around the placeholder that the dynamic controls get added to, so that when they respond to events, they refresh the updatepanel. This actually wor...

How to refresh a gridview after record insertion?
Hi all,I'm using a gridview to display records in a data table in ASP.NET 2.0 web pages, and use seperate combination of textboxes and button to take new records and insert into the data table.  The gridview is data-bound. How can I refresh the gridview to display newly added records every time after I hit a button to insert a new record into the database? Thanks Tony   GridView.DataBind()There are no stupid questions, only easy answers. However, the quality of assistance you receive (if any) is directly proportional to the quality of your request.p.s. Please...

Web resources about - GridView is not Refreshing after deleting record. How do i make it refresh. - asp.net.getting-started

Moke (墨客) — A Refreshing Weibo Client (刷新你的微博体验) for iPhone, iPod touch, and iPad on the iTunes App Store ...
Get Moke (墨客) — A Refreshing Weibo Client (刷新你的微博体验) on the App Store. See screenshots and ratings, and read customer reviews.

NSW election: Leaders' conduct makes a refreshing change
One of the most encouraging things to come out of Saturday night was Luke Foley's apparent willingness to join Mike Bard in lifting political ...

Socceroos certain also-rans: how refreshing
Australia is the 62nd-ranked soccer country in the world. In the other team sports dearest to Australians' hearts, there are not even 62 countries ...

WAG culture: Mirka Federer made a refreshing change
It really shouldn't be headline news, not in 2014, but so faultlessly has Mirka Federer conducted herself in the five years she has been married ...

Refreshing taste of diplomacy
The Scandinavians are heading south.

Refreshing way to brew a sector newbie
Nexba: refreshing way to brew an iced tea sector newbie

Justin Trudeau's Abortion Tweet About Women Is Pretty Refreshing
At a time when it can feel like women's rights are being determined by people who aren't, frankly, affected by them, one Canadian politician ...

Tea's refreshing change
Li Jiayi and her friends are happy to spend 1,000 yuan between them over a pot of tea.

This ‘Refreshing’ Document Review Job Ad Is Actually Just Annoying And Unprofessional
Does this company want document review attorneys or “camp counselors?” Continue reading » Follow Above the Law on Twitter or become a fan on ...

Coke Zero Even Makes PowerPoint A Bit More Refreshing
... that’s enough to suspect it’ll get passed around the office by basketball lovers. The post Coke Zero Even Makes PowerPoint A Bit More Refreshing ...

Resources last updated: 12/9/2015 6:43:06 PM