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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:00:36+00:00 2026-06-16T19:00:36+00:00

I have a gridview defined as <asp:UpdatePanel ID=up2 runat=server> <Triggers> <asp:AsyncPostBackTrigger ControlID=btnSubmit EventName=Click />

  • 0

I have a gridview defined as

 <asp:UpdatePanel ID="up2" runat="server">
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="btnSubmit" EventName="Click" />
    </Triggers>
    <ContentTemplate>
        <asp:GridView ID="GridView1" DataSourceID="employee" AutoGenerateEditButton="true" AutoGenerateDeleteButton="true" DataKeyNames="id" AllowPaging="true" AllowSorting="true" runat="server" CellPadding="4" ForeColor="#333333" 
            GridLines="None">
            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
            <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
            <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <EditRowStyle BackColor="#999999" />
            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
      </asp:GridView>   
      <asp:SqlDataSource ID="employee" runat="server" ConnectionString="values go here" SelectCommand="select * from employee" UpdateCommand="update employee set name=@name, company=@company, salary=@salary where id=@id" DeleteCommand="delete from employee where id=@id"></asp:SqlDataSource>        
    </ContentTemplate>
 </asp:UpdatePanel>

I need this to be updated each time the Submit button is clicked . The Submit button is defined as

 protected void btnSubmit_Click(object sender, EventArgs e)
{
    try
    {
        SqlConnection xconn = new SqlConnection();
        xconn.ConnectionString = @"values go here";
        xconn.Open();
        string str = "insert into employee(name, company, salary) values(@name, @company, @salary)";
        SqlCommand ycmd = new SqlCommand(str, xconn);
        ycmd.Parameters.Add("@name", txtname.Text);
        ycmd.Parameters.Add("@salary", txtsalary.Text);
        ycmd.Parameters.Add("@company", txtcompany.Text);
        ycmd.ExecuteNonQuery();
        lblresult.Text = "Record successfully inserted";            
    }
    catch (SqlException e1)
    {
        lblresult.Text = "<span style='color:red;'>" + e1.Message + "<br />" + e1.StackTrace + "</span>";
    }
    catch (Exception e2)
    {
        lblresult.Text = "<span style='color:red;'>" + e2.Message + "<br />" + e2.StackTrace + "</span>";
    }
    finally
    {
        txtname.Text = "";
        txtcompany.Text = "";
        txtsalary.Text = "";
    }
}

However, the grid does not get updated on btnSubmit_Click

What is a solution to this?

  • 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-06-16T19:00:37+00:00Added an answer on June 16, 2026 at 7:00 pm

    You need

    GridView1.DataBind();
    

    to force the grid to requery the data.

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

Sidebar

Related Questions

I have a GridView defined as follows: <asp:GridView ID=myGridView AutoGenerateColumns=false runat=server OnLoad=myGridView_Load OnRowCommand=myGridView_Command OnRowEditing=myGridView_RowEditing
I have a gridview which is defined as follows: <asp:GridView ID=ComponentGridView runat=server AutoGenerateColumns=true OnPageIndexChanging=ComponentGridView_PageIndexChanging
I have defined a nested grid view in the following way. <asp:GridView ID=GridView1 runat=server
I have a HyperLinkField defined as follows: <asp:GridView ID=gvNotifications runat=Server AutoGenerateColumns=false EnableViewState=true CssClass=tableWhole AlternatingRowStyle-CssClass=tableAlt>
I have defined the following in my gridview markup (simplified): <asp:GridView ID=grvReport runat=server DataSourceID=odsReport
I have a GridView defined like this: <asp:GridView ID=myGridView ruant=server> <asp:BoundField DataField=myField /> <asp:CommandField
How does asp.net parse the GridView? Suppose I have defined both EditItemTemplate and ItemTemplate.
<asp:GridView ID=grid1 runat=server AutoGenerateColumns=False> <Columns> <asp:BoundField DataField='id' HeaderText=Id Visible=False /> <asp:BoundField DataField='Name' Visible=True HeaderText=Full
Well i have a gridview where i have defined the columns on my own
i have a gridview which is populating from sql datasource defined at designed, i

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.