Monday, September 14, 2015

Sunny

using System; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using Microsoft.SharePoint; using System.Data; namespace VisualWebPartProject1.VisualWebPart1 { public partial class VisualWebPart1UserControl : UserControl { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { try { SPSite objSite = new SPSite("http://intranet.contoso.com"); SPWeb objWeb = objSite.OpenWeb(); SPList objList = objWeb.Lists["Employee"]; //DataTable dt = new DataTable(); //dt.Columns.Add("Name"); //dt.Columns.Add("Email ID"); //dt = objList.Items.GetDataTable(); this.GridView1.DataSource = objList.Items.GetDataTable(); this.GridView1.DataBind(); //get the emaployee id 1 and show in the text box SPListItem objItem = objList.GetItemById(1); this.txtName.Text = objItem["Title"].ToString(); this.txtEmilID.Text = objItem["Email ID"].ToString(); } catch (Exception ex) { this.Label1.Text = ex.Message; } } } protected void btnTest_Click(object sender, EventArgs e) { SPSite objSite = new SPSite("http://intranet.contoso.com"); SPWeb objWeb = objSite.OpenWeb(); SPList objList = objWeb.Lists["Employee"]; //get the emaployee id 1 and show in the text box SPListItem objItem = objList.GetItemById(1); objItem["Email ID"] = this.txtEmilID.Text; objItem.Update(); } } } ------------------------------------------------------------------- <%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %> <%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %> <%@ Import Namespace="Microsoft.SharePoint" %> <%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="VisualWebPart1UserControl.ascx.cs" Inherits="VisualWebPartProject1.VisualWebPart1.VisualWebPart1UserControl" %>
Name
Email ID

All The Employee