You must Sign In to post a response.
  • Category: Visual Studio

    Update Datagridview in database

    Hello everyone, I insert the datagridview control and I link it with a datasource but I stuck to the update with this datagridview when inserting new line in database?
  • #763208
    Hello ammar.Dev,

    You can do it by creating one function.

    public void bindgridview()
    {
    // Code to bind the gridview
    }

    protected void Page_Load(object sender, EventArgs e)
    {
    bindgridview();
    }

    protected void ButtonInsert_Click(object sender, EventArgs e)
    {
    // Code to insert your data to database
    bindgridview();
    }


    This will help you update the gridview with updated data.
    Let me know if you still facing the problem.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

  • #763324
    Hello,

    Check with the following code :-

    protected void Page_Load(object sender, EventArgs e)
    {
    if (!IsPostBack)
    {
    bindData();
    }
    }

    protected void Button1_OnClick(object sender, EventArgs e)
    {
    // insert data to database
    bindData();
    }

    public void bindData()
    {
    // retreive data from database to Dataset and DataTable
    gridview1.DataSource = ds; //provide the dataset or datatable object variable where data is retreived from database
    gridview1.DataBind();
    }



    Thanks


Sign In to post your comments