2
\$\begingroup\$

I am using this code to insert and retrieve:

namespace Gridwebpart.VisualWebPart1
{
    public partial class VisualWebPart1UserControl : UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                SPWeb site = SPContext.Current.Web;
                SPList list = site.Lists["GridList"];
                SPListItemCollection items = list.Items;
                DataTable dt = items.GetDataTable();
                Gridnames.DataSource = dt;
                Gridnames.DataBind();

            }

        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            SPWeb site = SPContext.Current.Web;
            SPList list = site.Lists["GridList"];
            SPListItemCollection items = list.Items;
            //SPListItem item = list.GetItemById(1);
            SPListItem item = items.Add();
            item["Title"] = txtName.Text;
            item["Description"] = txtDescription.Text;
            item["IS Sharepoint 2010 Developer"] = chkbox.Checked;
            item.Update();
            site.AllowUnsafeUpdates = false;
            txtName.Text = "";
            txtDescription.Text = "";
             chkbox.Checked=false;
             items = list.Items;
             DataTable dt = items.GetDataTable();
             Gridnames.DataSource = dt;
             Gridnames.DataBind();
        }
    }
}
\$\endgroup\$
  • \$\begingroup\$ Nope, looks like the textbook example to me. \$\endgroup\$ – Jesse C. Slicer Aug 29 '12 at 13:22
  • \$\begingroup\$ what if i use updatelistitems sharepoint web service \$\endgroup\$ – Rajesh Chowdary Aug 30 '12 at 5:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.