.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> SharePoint >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

update list item

Posted By:Sagar Pardeshi       Posted Date: February 09, 2011    Points: 15    Category: SharePoint    URL: http://www.dotnetspark.com  

Increment And update list item in sharepoint list on button click Event
 

protected void btnCount_Click(object sender, EventArgs e)

{

            try

            {

                        int iRegisterUser = 0;

                        using(SPSite site = new SPSite("http://sp2k10srvr01/sites/test/"))

                        {

                                    using(SPWeb web = site.OpenWeb())

                                    {

                                                SPList list = web.Lists["RegisterUsers"];

                                                SPListItem item = list.Items[0];                                      

                                                iRegisterUser = Convert.ToInt32(item["Register User"]);                                                                            

                                                iRegisterUser  = iRegisterUser + 1;

                                                item["Register User"] = Convert.ToString(iRegisterUser);

                                                item.Update();   

                                                list.Update();

                                                lblCount.Text = iRegisterUser.ToString(); 

                                    }

                        }

            }

            catch(Exception ex)

            {                      

                        Response.Write(ex.Message);

            }

}



     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend