In simple terms "When you create a custom list, a new empty list is created with just two columns - Title and Attachments. The list contains a single default view. Once you create the list, you can add more columns, views, and so on".
I think we are now good to go and implement this wonderful concept.
Step 1: Create a custom list and modify the view.
Step 2: Open SharePoint 2010 Central Administration and navigate to specific site.
Step 3: Open Visual Studio 2010 and create an "Empty SharePoint project":
Step 4: Select "Deploy as a farm solution" and click on the "Finish" button. Now an empty project will be created:
Step 5: Add a new visual webpart for that project:
Step 6: The complete code of visualwebpart1usercontrol.ascx looks like this:
<%@ Assembly Name="$
<%@ Assembly Name="Microsoft.
<%@ Register TagPrefix="
Assembly="Microsoft.
<%@ Register TagPrefix="
<%@ Register TagPrefix="asp" N
<%@ Import Namespace="
<%@ Register TagPrefix="
Assembly="Microsoft.
<%@ Control Language="C#" Aut
Inherits="
<div>
<center>
<table>
<tr>
<td colspan="
<asp:label
font-
</td>
</tr>
<tr>
<td>
<asp:label id="
font-
</td>
<td>
<asp:textb
</td>
</tr>
<tr>
<td>
<asp:label
font-
</td>
<td>
<asp:textb
</td>
</tr>
<tr>
<td>
<asp:label
font-
</td>
<td>
<asp:textb
</td>
</tr>
<tr>
<td>
<asp:label
font-
</td>
<td>
<asp:textb
</td>
</tr>
<tr>
<td colspan="
<asp:butto
backco
</td>
</tr>
<tr>
<td colspan="
<asp:label
</td>
</tr>
</table>
</center>
</div>
Step 7: The complete code of visualwebpart1usercontrol.ascx.cs looks like this:
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
namespace ListUpdateApplication.UpdateListWebPart
{
public partial class UpdateListWebPartUserControl : UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
TextBox4.Focus();
}
protected void Button1_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(TextBox4.Text))
{
Label5.Text = "Please Enter Some Values";
}
else
{
SPSite site = SPContext.Current.Site;
SPWeb web = site.OpenWeb();
web.AllowUnsafeUpdates = true;
SPList list = web.Lists["Student"];
SPListItem item = list.GetItemById(Convert.ToInt32(TextBox4.Text));
item["First Name"] = TextBox1.Text;
item["Last Name"] = TextBox2.Text;
item["Age"] = Convert.ToInt32(TextBox3.Text); item.Update();
Label5.Text = "Data Successfully Updated";
TextBox1.Text = string.Empty;
TextBox2.Text = string.Empty;
TextBox3.Text = string.Empty;
TextBox4.Text = string.Empty;
}
}
}
}
Step 8: Deploy the solution file and add the created webpart to the SharePoint site:
Step 9: The output of the application looks like this:
Step 10: When updating the list the output of the application looks like this:
No comments:
Post a Comment