<%@ 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="InsertRamUserControl.ascx.cs"
Inherits="RamProject.InsertRam.InsertRamUserControl"
%>
<table cellpadding="1" cellspacing=".5" align="center"
style="border: medium double
#FF00FF; background: #FFFFCC; height: 108px;"
width="400">
<tr><td colspan="2" align="center"></td></tr>
<tr><td> FirstName</td><td>
<asp:TextBox ID="txtFirstName"
runat="server"></asp:TextBox>
<asp:RequiredFieldValidator
ID="rfvfirstName"
runat="server"
ControlToValidate="txtFirstName"
Display="Dynamic"
ErrorMessage="*"
ToolTip="The
First Name can not blanks ?"
EnableClientScript="true"
SetFocusOnError="true"
ForeColor="Red"
></asp:RequiredFieldValidator>
</td></tr>
<tr><td> LastName</td><td>
<asp:TextBox ID="txtLastName"
runat="server"></asp:TextBox>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator1"
runat="server"
ControlToValidate="txtLastName"
Display="Dynamic"
ErrorMessage="*"
ToolTip="The
Last Name can not blanks ?" EnableClientScript="true"
SetFocusOnError="true"
Text="*" ForeColor="Red"
></asp:RequiredFieldValidator>
</td></tr>
<tr><td> MobileNo</td><td>
<asp:TextBox ID="txtMobileNo"
runat="server"
></asp:TextBox>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator2"
runat="server"
ControlToValidate="txtMobileNo"
Display="Dynamic"
ErrorMessage="*"
ToolTip="The
Mobile No. can not blanks ?" EnableClientScript="true" SetFocusOnError="true"
Text="*" ForeColor="Red"
></asp:RequiredFieldValidator>
<%--<asp:RegularExpressionValidator Display =
"Dynamic"
ControlToValidate =
"txtMobileNo" ID="revMobileNo"
ValidationExpression
="^[\s\S]{8,15}$" runat="server"
ErrorMessage="Mobile No Only
no."
Font-Size="X-Small"
ForeColor="Red"
></asp:RegularExpressionValidator>--%>
</td></tr>
<tr><td> Email ID</td><td>
<asp:TextBox ID="txtEmailID"
runat="server"></asp:TextBox>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator3"
runat="server"
ControlToValidate="txtEmailID"
Display="Dynamic"
ErrorMessage="*"
ToolTip="The Email
Id can not blanks ?" EnableClientScript="true" SetFocusOnError="true"
Text="*" ForeColor="Red"
></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator
ID="REVEMailID"
runat="server"
ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
ControlToValidate="txtEmailID"
ErrorMessage="Input
Valid Email ID ?"
Font-Size="X-Small"
ForeColor="Red"
></asp:RegularExpressionValidator>
</td></tr>
<tr><td> UserName</td><td>
<asp:TextBox ID="txtUserName"
runat="server"></asp:TextBox>
<asp:RequiredFieldValidator
ID="REVUsername"
runat="server"
ControlToValidate="txtUserName" ErrorMessage="*"
ToolTip="The User name can not blanks ?"></asp:RequiredFieldValidator>
</td></tr>
<tr><td> Pasword</td><td>
<asp:TextBox ID="txtPassWord"
runat="server"
TextMode="Password"
></asp:TextBox>
</td></tr>
<tr><td align="center">
</td>
<td>
<asp:Button ID="btnSave"
runat="server"
Text="Submit
" OnClick="btnSave_Click" />
<asp:Button ID="btnSaveAddmore"
runat="server" Text="Submit Add More "
onclick="btnSaveAddmore_Click"
/>
<asp:Button ID="btnCancel"
runat="server"
Text="Cancel"
onclick="btnCancel_Click"
CausesValidation="False"
/>
</td>
</tr>
</table>
Code
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
namespace RamProject.InsertRam
{
public partial class InsertRamUserControl
: UserControl
{
protected void
Page_Load(object sender, EventArgs e)
{
}
protected void
btnSave_Click(object sender, EventArgs e)
{
try
{
RamProjectBussinesMaster.RamProjecBussinessMaster
objBussinessManager = new RamProjectBussinesMaster.RamProjecBussinessMaster();
RamProjectEntity.RamProjectEntity
objEntity = new RamProjectEntity.RamProjectEntity();
objEntity.UserName = txtUserName.Text;
objEntity.PassWord = txtPassWord.Text;
objEntity.FirstName = txtFirstName.Text;
objEntity.LastName = txtLastName.Text;
objEntity.EmailID = txtEmailID.Text;
objEntity.MobileNO = txtMobileNo.Text;
object obj = (object)objEntity;
objBussinessManager.InsertSample(obj);
txtUserName.Text = String.Empty;
txtPassWord.Text = String.Empty;
txtFirstName.Text = "";
txtLastName.Text = "";
txtMobileNo.Text = "";
txtEmailID.Text = "";
Response.Redirect("http://win-4ibnt6tq8js:31367/SitePages/LoginGridMaster.aspx");
}
catch
{
}
}
protected void
btnSaveAddmore_Click(object sender, EventArgs e)
{
}
protected void
btnCancel_Click(object sender, EventArgs e)
{
}
}
}
Bussiness Page
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
namespace RamProjectBussinesMaster
{
public class RamProjecBussinessMaster
{
public void
InsertSample(object obj)
{
try
{
RamProjectEntity.RamProjectEntity
objEntity = new RamProjectEntity.RamProjectEntity();
objEntity = (RamProjectEntity.RamProjectEntity)obj;
SPListItemCollection myColl = SPContext.Current.Web.Lists["Login"].Items;
SPListItem item = myColl.Add();
item["Title"]
= objEntity.UserName;
item["PassWord"] =
objEntity.PassWord;
item["FirstName"] =
objEntity.FirstName;
item["LastName"] =
objEntity.LastName;
item["MobileNumber"] =
objEntity.MobileNO;
item["EmailID"] =
objEntity.EmailID;
item.Update();
}
catch
{
}
}
}
}
Entity Page
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace RamProjectEntity
{
public class RamProjectEntity
{
public int ID;
public string
UserName;
public string
PassWord;
public string
EmailID;
public String
MobileNO;
public String
FirstName;
public String
LastName;
//public string strUserName
//{
// get
// {
// return
UserName;
// }
// set
// {
// UserName =
value;
// }
//}
//public string strPassWord
//{
// get
// {
// return
PassWord;
// }
// set
// {
// PassWord =
value;
// }
//}
}
}
Grid Page
<%@ 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="LoginGridMasterUserControl.ascx.cs"
Inherits="ThreeLayers.LoginGridMaster.LoginGridMasterUserControl"
%>
<script type="text/javascript">
function fnConfirm() {
if (confirm("The item
will be deleted. Are you sure want to continue?") == true)
return true;
else
return false;
}
</script>
<asp:GridView ID="dgvDDLBindsample" runat="server" AutoGenerateColumns="False" Width="600px"
CellPadding="4" ForeColor="#333333"
GridLines="None"
DataKeyNames="ID"
onrowcommand="dgvDDLBindsample_RowCommand"
>
<AlternatingRowStyle
BackColor="White"
/>
<Columns>
<asp:TemplateField HeaderText="ItemID"
HeaderStyle-HorizontalAlign="Left" Visible="false">
<ItemTemplate>
<%# Eval("ID")
%>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="lblItemID"
runat="server"
Text='<%# Eval("ID") %>' Columns="3" />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Login
ID" HeaderStyle-HorizontalAlign="Left">
<ItemTemplate>
<%# Eval("Title")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtUserName"
runat="server"
Text='<%# Eval("Title") %>' Columns="3" />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="PassWord"
HeaderStyle-HorizontalAlign="Left">
<ItemTemplate>
<%# Eval("PassWord")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtPassWord"
runat="server"
Text='<%# Eval("PassWord") %>' Columns="3" />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="First
Name" HeaderStyle-HorizontalAlign="Left">
<ItemTemplate>
<%# Eval("FirstName")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtFirstName"
runat="server"
Text='<%# Eval("FirstName") %>' Columns="3" />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Last
Name" HeaderStyle-HorizontalAlign="Left">
<ItemTemplate>
<%# Eval("LastName")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtLastName"
runat="server"
Text='<%# Eval("LastName") %>' Columns="3" />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Mobile
Number" HeaderStyle-HorizontalAlign="Left">
<ItemTemplate>
<%# Eval("MobileNumber")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtMobileNo"
runat="server"
Text='<%# Eval("MobileNumber") %>' Columns="3" />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Email
ID" HeaderStyle-HorizontalAlign="Left">
<ItemTemplate>
<%# Eval("EmailID")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtEmailID"
runat="server"
Text='<%# Eval("EmailID") %>' Columns="3" />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="" HeaderStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:LinkButton ID="imgbtnEdit" ImageAlign="Middle" Text="Edit" runat="server" ToolTip="Edit"
CommandName="Edit"
/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Action">
<ItemTemplate>
<asp:LinkButton ID="lbDelete"
runat="server"
OnClick="lbDelete_Click"
OnClientClick="return
fnConfirm();"> Delete</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#990000"
Font-Bold="True"
ForeColor="White"
/>
<HeaderStyle BackColor="#990000"
Font-Bold="True"
ForeColor="White"
/>
<PagerStyle BackColor="#FFCC66"
ForeColor="#333333"
HorizontalAlign="Center"
/>
<RowStyle BackColor="#FFFBD6"
ForeColor="#333333"
/>
<SelectedRowStyle
BackColor="#FFCC66"
Font-Bold="True"
ForeColor="Navy"
/>
</asp:GridView>
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
namespace ThreeLayers.LoginGridMaster
{
public partial class LoginGridMasterUserControl
: UserControl
{
protected void
Page_Load(object sender, EventArgs e)
{
//dgvDDLBindsample.RowDataBound += new
GridViewRowEventHandler(dgvDDLBindsample_RowDataBound);
////dgvDDLBindsample.RowEditing += new
GridViewEditEventHandler(dgvDDLBindsample_RowEditing);
////dgvDDLBindsample.RowUpdating += new
GridViewUpdateEventHandler(dgvDDLBindsample_RowUpdating);
//dgvDDLBindsample.RowDeleting += new
GridViewDeleteEventHandler(dgvDDLBindsample_RowDeleting);
////dgvDDLBindsample.RowCancelingEdit
+= new GridViewCancelEditEventHandler(dgvDDLBindsample_RowCancelingEdit);
if (!IsPostBack)
{
getData();
}
}
public void getData()
{
try
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
SPWeb currentWeb = SPContext.Current.Web;
SPList lst = currentWeb.Lists["Login"];
SPQuery sQuery = new SPQuery();
sQuery.Query = "<OrderBy><FieldRef
Name='ID' /></OrderBy>";
SPListItemCollection myColl =
lst.GetItems(sQuery);
if (myColl.Count > 0)
{
dgvDDLBindsample.DataSource = myColl.GetDataTable();
dgvDDLBindsample.DataBind();
}
});
}
catch (Exception
Ex)
{
}
}
protected void
lbDelete_Click(object sender, EventArgs e)
{
string strItemID1;
LinkButton lnkbtn = sender as LinkButton;
GridViewRow grdRow = lnkbtn.NamingContainer as GridViewRow;
strItemID1 =
dgvDDLBindsample.DataKeys[grdRow.RowIndex].Value.ToString();
SPSecurity.RunWithElevatedPrivileges(delegate()
{
DeleteRow(strItemID1);
getData();
});
}
public void
DeleteRow(string ItemIDNew)
{
SPWeb currentWeb = SPContext.Current.Web;
SPList lst = currentWeb.Lists["Login"];
SPListItem item = null;
item = lst.GetItemById(int.Parse(ItemIDNew));
currentWeb.AllowUnsafeUpdates = true;
item.Delete();
lst.Update();
currentWeb.AllowUnsafeUpdates = false;
}
protected void
dgvDDLBindsample_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Edit")
{
AppCode.EntityClass objEntityClass = new AppCode.EntityClass();
GridViewRow row = (GridViewRow)((Control)e.CommandSource).NamingContainer;
objEntityClass.ID = Convert.ToInt32(dgvDDLBindsample.DataKeys[row.RowIndex].Value);
int LoginId = objEntityClass.ID;
Response.Redirect("http://win-4ibnt6tq8js:31367/SitePages/TreeLayerLoginpage.aspx?LoginId="
+ LoginId);
}
}
//void dgvDDLBindsample_RowDataBound(object sender,
GridViewRowEventArgs e)
//{
// try
// {
// if
(e.Row.RowState == DataControlRowState.Edit || (e.Row.RowState ==
(DataControlRowState.Edit | DataControlRowState.Alternate)))
// {
// SPWeb
currentWeb = SPContext.Current.Web;
// SPList
lst = currentWeb.Lists["Country LookUp"];
// SPQuery
sQuery = new SPQuery();
//
sQuery.Query = "<OrderBy><FieldRef Name='ID'
/></OrderBy>";
//
SPListItemCollection myColl = lst.GetItems(sQuery);
//
DropDownList ddlCountryNew = e.Row.FindControl("ddlCountry")
as DropDownList;
// if
(myColl.Count > 0)
// {
//
ddlCountryNew.DataValueField = "ID";
//
ddlCountryNew.DataTextField = "Title";
//
ddlCountryNew.DataSource = myColl.GetDataTable();
//
ddlCountryNew.DataBind();
// }
//
ddlCountryNew.Items.Insert(0, new ListItem("--Select
Country--"));
// int strItemID =
int.Parse(dgvDDLBindsample.DataKeys[e.Row.RowIndex].Value.ToString());
// SPList
lstGlobalClients = currentWeb.Lists["Global Clients"];
// SPQuery
strFindLookUpValue = new SPQuery();
// strFindLookUpValue.Query =
"<Where><Eq><FieldRef Name='ID' /><Value
Type='Counter'>" + strItemID +
"</Value></Eq></Where>";
//
SPListItemCollection GlobalClientsColl =
lstGlobalClients.GetItems(strFindLookUpValue);
// if (GlobalClientsColl.Count > 0)
// {
//
SPListItem item = GlobalClientsColl[0];
//
SPFieldLookupValue value = new
SPFieldLookupValue(item["ID"].ToString());
// for
(int i = 0; i < ddlCountryNew.Items.Count; i++)
// {
//
if (value.LookupId.ToString() == ddlCountryNew.Items[i].Value)
//
{
//
ddlCountryNew.SelectedIndex = i;
//
break;
//
}
// }
// }
// }
// }
// catch
(Exception Ex)
// {
//
lblMessage.Text = Ex.ToString();
// }
//}
//protected void dgvDDLBindsample_RowDeleting(object
sender, GridViewDeleteEventArgs e)
//{
//try
//{
// strItemID1 =
dgvDDLBindsample.DataKeys[e.RowIndex].Value.ToString();
//
SPSecurity.RunWithElevatedPrivileges(delegate()
// {
//
DeleteRow(strItemID1);
// getData();
// });
//}
//catch (Exception ex)
//{
// Response.Write(ex.ToString());
//}
//}
//public void updateRow(string ItemID1, string Title,
string CountryLookUP)
//{
// SPWeb
currentWeb = SPContext.Current.Web;
// SPList lst =
currentWeb.Lists["Global Clients"];
// SPListItem item
= null;
// item =
lst.GetItemById(int.Parse(ItemID1));
//
currentWeb.AllowUnsafeUpdates = true;
//
item["Title"] = Title;
//
item["Country"] = CountryLookUP;
// item.Update();
// lst.Update();
//
currentWeb.AllowUnsafeUpdates = false;
//}
//void dgvDDLBindsample_RowCancelingEdit(object sender,
GridViewCancelEditEventArgs e)
//{
// try
// {
//
dgvDDLBindsample.EditIndex = -1;
//
SPSecurity.RunWithElevatedPrivileges(delegate()
// {
//
getData();
// });
// }
// catch
(Exception Ex)
// {
//
lblMessage.Text = Ex.ToString();
// }
//}
//void dgvDDLBindsample_RowUpdating(object sender,
GridViewUpdateEventArgs e)
//{
// try
// {
// Label lbl =
(Label)dgvDDLBindsample.Rows[e.RowIndex].Cells[1].FindControl("lblItemID");
// TextBox
txtTitle1 =
(TextBox)dgvDDLBindsample.Rows[e.RowIndex].Cells[2].FindControl("txtTitle");
//
DropDownList ddlCountryNew =
(DropDownList)dgvDDLBindsample.Rows[e.RowIndex].Cells[3].FindControl("ddlCountry");
// int
LookUpValue = int.Parse(ddlCountryNew.SelectedValue.ToString());
// string
LookUpValue1 = ddlCountryNew.SelectedItem.ToString();
//
updateRow(lbl.Text, txtTitle1.Text, LookUpValue1);
//
dgvDDLBindsample.EditIndex = -1;
// getData();
// }
// catch
(Exception Ex)
// {
//
lblMessage.Text = Ex.ToString();
// }
//}
//void dgvDDLBindsample_RowEditing(object sender,
GridViewEditEventArgs e)
//{
// try
// {
//
dgvDDLBindsample.EditIndex = e.NewEditIndex;
//
SPSecurity.RunWithElevatedPrivileges(delegate()
// {
//
getData();
// });
// }
// catch
(Exception Ex)
// {
//
lblMessage.Text = Ex.ToString();
// }
//}
}
}