Click here to Skip to main content
15,943,210 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
sir I want grid view getting updated after inserting data OR when i delete row by clicking buttton the grid view cannot show updated database values.
Posted
Updated 8-Jan-12 21:31pm
v2

C#
public void GridLoad()
{
with grid
.datasource=dataset(or)datatable
.databind()
end with
}
protected void btnDelete_Click(object sender, EventArgs e)
 {
    // Some code here...
    // Code for deleting here...
    this.upGrid1.Update();
gridload()//call 
 }
 
Share this answer
 
Hi friend,

after delete,insert and update command fired then you need to rebind your grid.
if you again rebind your grid it will show latest record.

Hope it will helps you and let me know if you want to more information.
 
Share this answer
 
on gridview_rowdeleting event and rowupdating event

bind your gridviw.

put your gridview binding code in a separate method suppose bindGriddata()

then call bindgriddata() method in rowdeleting and updating events.
 
Share this answer
 
Hi,
Use <asp:updatepanel xmlns:asp="#unknown">

Example:
In client code:
C#
<tr id="trViewDetails"  runat="server">
   <td align="left" valign="top" style="padding-removed 10px;">
      <asp:UpdatePanel ID="upGrid1" runat="server" UpdateMode="Conditional">
          <ContentTemplate>
             <asp:GridView ID="GridView1" runat="server">
                 <%--  some code here...--%>
             </asp:GridView>
          </ContentTemplate>
      </asp:UpdatePanel>
      <asp:Button ID="btnDelete" runat="server" Text="Delete" 
      onclick="btnDelete_Click" />
      <br />
   </td>
</tr>


in you code behind:
C#
protected void btnDelete_Click(object sender, EventArgs e)
{
   // Some code here...
   // Code for deleting here...
   this.upGrid1.Update();
}


Thanks Mehdi for corection...
<asp:button id="btnDelete" runat="server" text="Delete">
onclick="btnDelete_Click" />
but still have one...


Regards,
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900