dotnetspider.com
Login Login    Register      

TutorialsForumCareer DevelopmentResourcesReviewsJobsInterviewCommunitiesProjectsTraining

Subscribe to Subscribers
Talk to Webmaster
Tony John

Facebook
Google+
Twitter
LinkedIn
Online MembersJayant Tripathy
Ultimaterengan
parthiban
NIRVANA
nitz
More...
Join our online Google+ community for Bloggers, Content Writers and Webmasters




Forums » .NET » ASP.NET »

Deleting data from grid view and displaying it back by button clicks.


Posted Date: 08 Aug 2012      Posted By:: Naren     Member Level: Silver    Member Rank: 1585     Points: 5   Responses: 5



Hi,

I need a help in my following code:

I have two buttons view and clear. I want to view gridview after inserting a row by clicking the view button. Then by clicking the clear button I want to clear both gridview and database.

My code is:
protected void btnview_Click(object sender, EventArgs e)
{
GridView1.Visible = true;


}
protected void btncleardb_Click(object sender, EventArgs e)
{
GridView1.Columns.Clear();
GridView1.Visible = true;

}


If I click view button after inserting the data, I can see the updated gridview and it is getting cleared when I click clear button. But if I click view button again after adding data again, grid view is not displaying.

Please help me in this regard.

Thanks.

Naren Kumar.




Responses

#683541    Author: Asheej T K        Member Level: Diamond      Member Rank: 2     Date: 08/Aug/2012   Rating: 2 out of 52 out of 5     Points: 3

Hi Naren Kumar,

You are not re-binding your gridview to show the newly added data. In the view button click event you need to call the method used to bind the gridview again if you wanted to display latest data from the database.


protected void btnview_Click(object sender, EventArgs e)
{
GridView1.Visible = true;
BindGridView();//Function to bind the gridview
}


Let me know if you need any more details regarding this.


Regards,
Asheej T K
Microsoft MVP[ASP.NET/IIS]
DotNetSpider MVM

Dotnet Galaxy



 
#683550    Author: Naren      Member Level: Silver      Member Rank: 1585     Date: 08/Aug/2012   Rating: 2 out of 52 out of 5     Points: 1

Hi Asheej,

Thanks for your reply. I coundn't find BindGridView() function in the popup. I might missing some namespace. But I used "gridview1.databind();" . Now I can able to see updated gridtable in my page.

Thanks.

Naren Kumar.



 
#683603    Author: Ravindran        Member Level: Diamond      Member Rank: 3     Date: 08/Aug/2012   Rating: 2 out of 52 out of 5     Points: 4

Hi,

Because reason was your not bind data into the gridview


protected void btnview_Click(object sender, EventArgs e)
{
GridView1.Visible = true;
GridData();
}

//here i write common method call again wherever i required
void GridData()
{
sqlcmd = new SqlCommand("select * from emp", sqlcon);
sqlcon.Open();
da = new SqlDataAdapter(sqlcmd);
dt.Clear();
da.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
sqlcon.Close();
}


Regards
N.Ravindran
Your Hard work never fails






 
#683609    Author: Ajatshatru Upadhyay      Member Level: Gold      Member Rank: 19     Date: 08/Aug/2012   Rating: 2 out of 52 out of 5     Points: 3

Hi,

What Asheej is trying to say is you have to bind the gridview in the button click event. So just call the function in which you are binding the gridview.

If you are binding the gridview in page load, just make a separate function for that and call it from page load as well as from button click event.

Hope it'll help you.
Regards
Ajatshatru



 
#683624    Author: Naren      Member Level: Silver      Member Rank: 1585     Date: 08/Aug/2012   Rating: 2 out of 52 out of 5     Points: 1

Hi All,

Thanks for your updates. Added databind function in my code. Its working!

Very thanks.

Regards,
Naren.



 
Post Reply
You must Sign In to post a response.

Next : GMail Mails To Retrieve
Previous : Error while editing in dropdownlist..Object reference not set to an instance of an object.
Return to Discussion Forum
Post New Message
Category:

Related Messages



Follow us on Twitter: https://twitter.com/dotnetspider

Active Members
TodayLast 7 Daysmore...

Awards & Gifts
Email subscription
  • .NET Jobs
  • .NET Articles
  • .NET Forums
  • Articles Rss Feeds
    Forum Rss Feeds


    About Us    Contact Us    Copyright    Privacy Policy    Terms Of Use    Revenue Sharing sites   Advertise   Talk to Tony John
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2012 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.