Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6915275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:27:18+00:00 2026-05-27T09:27:18+00:00

I have a datagrid to display some information from a SQL table, and then

  • 0

I have a datagrid to display some information from a SQL table, and then a simple textbox and button to allow users to add records to the database. Problem is, when the user clicks Add, the datagrid SHOULD update, but it doesn’t, any ideas? The code in question is as follows:

protected void Page_Load(object sender, EventArgs e)
    {
        username.Text = Session["username"].ToString();
        datetime.Text = DateTime.Now.ToString();

        BindData();
    }

protected void BindData()
    {
        string SQLQuery = "SELECT * From Filters";

        OleDbConnection MyConn = new OleDbConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);

        DataSet resultsDataSet = new DataSet();
        MyConn.Open();

        OleDbDataAdapter DataAdapter = new OleDbDataAdapter(SQLQuery, MyConn);
        DataAdapter.Fill(resultsDataSet);
        DGFilters.DataSource = resultsDataSet;
        DGFilters.DataBind();

        if (resultsDataSet.Tables[0].Rows.Count == 0)
        {
            no_records.Visible = true;
            DGFilters.Visible = false;
        }
        else
        {
            DGFilters.Visible = true;
            no_records.Visible = false;
        }

        MyConn.Close();
    }

    protected void AddFilter_Click(object sender, EventArgs e)
    {
        OleDbConnection MyConn = new OleDbConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);

        MyConn.Open();

        string SQLInsert = "INSERT INTO Filters (FilterString) VALUES ( '" + FilterToAdd.Text + "')";

        OleDbCommand MyCmd = new OleDbCommand(SQLInsert, MyConn);

        MyCmd.ExecuteNonQuery();

        MyConn.Close();

        DataBind();

    }

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T09:27:18+00:00Added an answer on May 27, 2026 at 9:27 am

    At the bottom of your AddFilter_Click method you need to call your own BindData() so the grid can be refreshed with the new record. Right now you’re calling DataBind(), which is a method on the base class Control, which is being applied to your entire web form. I’m guessing this isn’t doing much of anything.

    Also, in your Page_Load method, you can probably change this:

    BindData();
    

    to

    if (!Page.IsPostBack)
         BindData();
    

    so that you don’t bind your grid twice when the user clicks on the ‘add’ button.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to display information in datagrid some information is about 1000 record from
Hey guys, I have an application that I want to display some data from
I am trying to add some styles in some DataGrid s I have. I
I'm writing a simple app to display some data on a DataGrid. The data
I have a datagrid in which I display several objects with some columns. I
I have a WPF app that uses DataGrid to display some data. When I
I have a datagrid getting bound to a dataset, and I want to display
I have a DataGrid with 5 template columns, However when I try and add
I am using the WPF toolkit datagrid to display some data and want to
Currently I have a DataGridView in my app which I fill from my Linq-to-SQL

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.