user963070
user963070

Reputation: 639

code-behind update of asp.net gridview

I have a GridView that is updated by code-behind code updating the SQL source by inputing text in a TextBox and clocking a button. I have been searching for how to update the GridView after updating the SQL source, and I didn't find the answer. My code for the button click and SQL source changes are:

protected void btnSubmit_Click(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
         sqlSource.InsertParameters["x"].DefaultValue = User.Identity.Name.ToString();
         sqlSource.InsertParameters["y"].DefaultValue = ((TextBox)this.FindControl("abc")).Text;
         sqlSource.InsertParameters["z"].DefaultValue = DateTime.Now.ToString();
         sqlSource.Insert(); 
    }
}

What do I add to this function so that the GridView is updated when the button is pressed?

Upvotes: 0

Views: 487

Answers (1)

amit ghosh
amit ghosh

Reputation: 276

Button click on ASP.NET need to be post back always. you write code just like page load event.

and for bind gridview from code write.

gridview1.datasource = sqlSource;
gridview1.Databind();

Upvotes: 2

Related Questions