Reputation: 165
I am working on an Asp.net, C# Application. I want to Refresh the webpage after I clicking on “Update” LinkButton; in Grid view. I have tried the following code; however it just refreshes the page without saving the updated data in Grid view.
protected void LinkButton1_Click1(object sender, EventArgs e)
{
Response.Redirect(Request.RawUrl.ToString());
}
Name of DataSource SqlDataSourcePlan
SELECT [PlanID], [Deposit], [DepositReturn], [Discount] FROM [PaymentPlan] WHERE ([Ref] = @Ref)
UPDATE [PaymentPlan] SET [Deposit] = @Deposit, [DepositReturn] = @DepositReturn, [Discount] = @Discount WHERE [PlanID] = @original_PlanID
Upvotes: 1
Views: 2442
Reputation: 460340
Use RawUrl
instead:
Response.Redirect(Request.RawUrl)
The raw URL is defined as the part of the URL following the domain information. In the URL string http://www.contoso.com/articles/recent.aspx, the raw URL is /articles/recent.aspx. The raw URL includes the query string, if present.
Edit: "without saving the updated data in Grid view"
Why do you think that redirecting the page to itself should save something somewhere?
Have a look at this tutorial: Inserting, Updating, and Deleting Data with the SqlDataSource (C#)
I assume that you actually want to update the GridView instead of the whole page. Then you should call GridView.DataBind()
.
Upvotes: 2
Reputation: 1941
My guess (without some other informations in the code it is difficult to say) is that althought the information is saved in the database, the datasource
for the gridview
is not refreshed with the new values.
I have seen this problem often regarding this part.
You have to rebind the gridview with Page.DataBind
or GridViewName.DataBind()
(where GridViewName
is the name of your gridview
) before the redirect.
You probably don't reload the GridView at PageLoad
or PageLoad
does not occure (can't know without the server code). If that would work properly, you would not need the databinding before redirecting.
Upvotes: 0