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 6108013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:15:03+00:00 2026-05-23T14:15:03+00:00

I am trying to refresh the grid-view after insert but it’s not working for

  • 0

I am trying to refresh the grid-view after insert but it’s not working for me, here is my code:

<asp:TextBox ID="TimeBox" runat="server" />
                <asp:TextBox ID="CommentBox" runat="server" TextMode="MultiLine" />
                    <asp:Button ID="insButton" runat="server" OnClick="insert" Text="Insert" />
<asp:GridView ID="MainGrid" runat="server">
</asp:GridView>

and here is the code behind:

    protected void Page_Load(object sender, EventArgs e)
{
    // filling the grid view

    SqlConnection conn = new SqlConnection (@"connectionString");
    SqlCommand cmd = new SqlCommand("SELECT tim,com FROM ten",conn);
    conn.Open();

    DataSet ds = new DataSet();
    SqlDataAdapter da = new SqlDataAdapter(cmd);
    da.Fill(ds);

    MainGrid.DataSource = ds;
    MainGrid.DataBind();  
}

protected void insert(object sender, EventArgs e) //adding the comments 
{
    SqlConnection conn = new SqlConnection(@"connectionString");
    SqlCommand cmd = new SqlCommand("INSERT INTO tennis (tim,com) VALUES (@tim,@com)", conn);
    cmd.Parameters.AddWithValue("@tim", TimBox.Text);
    cmd.Parameters.AddWithValue("@com", ComBox.Text);

    conn.Open();
    cmd.ExecuteNonQuery();
    MainGrid.DataBind();
    conn.Close();
}

the insert works fine and i can see the data if I refresh the page but I am trying to refresh the grid view only without refreshing the page.

  • 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-23T14:15:04+00:00Added an answer on May 23, 2026 at 2:15 pm

    After inserting the new record, you have to re-query the database and rebind the grid (same as you do in Page_Load) with a datasource which includes the new, inserted record.

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

Sidebar

Related Questions

I'm trying to refresh my main view in this code. It shows the right
I am trying to refresh asp.net label contorls outside the grid when I change
I am trying to create a user interface, but when I refresh the page,
I am trying to refresh the @ManyToMany relation but it gets cleared instead... My
I'm trying to refresh update panel via Javascript: __doPostBack(<%=upMyPanel.ClientID %>, ); But somehow its
I am trying to do something really simple, but somehow not getting the direction.
I'm trying to refresh a classic report with this code and it works fine
I am trying to refresh a page, but WANT to use the cache and
I am trying to wirte a refresh condition if the jquery dialogs are not
I'm trying to use tkinter to periodically refresh a square grid. Each square in

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.