protected void bt_add_Click1(object sender, EventArgs e)
{
Label6.Text = string.Empty;
AddtoList();
Label6.Visible = true;
}
protected void bt_view_Click(object sender, EventArgs e)
{
Gridview();
}
protected void bt_update_Click(object sender, EventArgs e)
{
Update();
clear();
}
protected void btn_reset_Click(object sender, EventArgs e)
{
clearcontrols();
Label6.Text = string.Empty;
}
protected void bt_delete_Click(object sender, EventArgs e)
{
Delete();
txt_Item.Text = string.Empty;
}
protected void StuList_Grid_PageIndexChanged(object sender, GridPageChangedEventArgs e)
{
StuList_Grid.CurrentPageIndex = e.NewPageIndex;
StuList_Grid.Visible = true;
SPList taskList = SpListitems();
DataTable tablelist = taskList.Items.GetDataTable();
StuList_Grid.DataSource = tablelist;
StuList_Grid.DataBind();
}
protected void Page_Load(object sender, EventArgs e)
{
}
#endregion
#region Methods
//This method will display the sharepoint list items to Grid and
//Show listitems in textboxes by id.
private void Gridview()
{
if (txt_Item.Text == string.Empty)
{
try
{
StuList_Grid.Visible = true;
Descending();
StuList_Grid.CurrentPageIndex = 0;
SPList taskList = SpListitems();
DataTable tablelist = taskList.Items.GetDataTable();
StuList_Grid.DataSource = tablelist;
StuList_Grid.DataBind();
Label6.Text = string.Empty;
}
catch (Exception ex)
{
ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(),
"AlertScript", "(function(){var f = function(){alert('not viewed', 370,210);Sys.Application.remove_load(f) ;};Sys.Application.add_load(f) ;})();", true);
}
}
else
{
StuList_Grid.Visible = false;
SPList taskList = SpListitems();
int id = Convert.ToInt32(txt_Item.Text);
SPListItem item = null;
try
{
item = taskList.GetItemById(id);
}
catch (Exception ex)
{
Label6.Text = "Item doesnot Exist";
}
if (item != null)
{
if (item["StuName"] != null)
{
txt_name.Text = item["StuName"].ToString();
}
else
txt_name.Text = string.Empty;
if (item["Department"] != null)
{
txt_dept.Text = item["Department"].ToString();
}
else
txt_dept.Text = string.Empty;
if (item["Location"] != null)
{
txt_location.Text = item["Location"].ToString();
}
else
txt_location.Text = string.Empty;
if (item["ContactNumber"] != null)
{
txt_number.Text = item["ContactNumber"].ToString();
}
else
txt_number.Text = string.Empty;
Label6.Text = string.Empty;
}
}
}
//This will add textbox values to sharepoint list.
private void AddtoList()
{
try
{
SPList taskList = SpListitems();
SPListItem listitem = taskList.Items.Add();
listitem["StuName"] = txt_name.Text;
listitem["Department"] = txt_dept.Text;
listitem["Location"] = txt_location.Text;
listitem["ContactNumber"] = txt_number.Text;
listitem.Update();
Label6.Text = "Records Saved";
clearcontrols();
Descending();
grid();
}
catch (Exception ex)
{
ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(),
"AlertScript", "(function(){var f = function(){alert('not inserted', 370,210);Sys.Application.remove_load(f) ;};Sys.Application.add_load(f) ;})();", true);
}
}
//This will update the list items by id
private void Update()
{
try
{
if (txt_Item.Text == string.Empty)
{
Label6.Text = "ID value is Required";
}
SPList taskList = SpListitems();
SPListItem item = null;
int id = Convert.ToInt32(txt_Item.Text);
try
{
item = taskList.GetItemById(id);
}
catch (Exception ex)
{
Label6.Text = "Item doesnot Exist";
}
if (item != null)
{
item["StuName"] = txt_name.Text;
item["Department"] = txt_dept.Text;
item["Location"] = txt_location.Text;
item["ContactNumber"] = txt_number.Text;
item.Update();
taskList.Update();
Label6.Text = "Updated";
grid();
}
}
catch (Exception ex)
{
ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(),
"AlertScript", "(function(){var f = function(){alert('Not Updated', 370,210);Sys.Application.remove_load(f) ;};Sys.Application.add_load(f) ;})();", true);
}
}
//This will delete the list items by id
private void Delete()
{
try
{
if (txt_Item.Text == string.Empty)
{
Label6.Text = "ID value is Required";
}
else
{
SPList taskList = SpListitems();
SPListItem item = null;
int id = Convert.ToInt32(txt_Item.Text);
try
{
item = taskList.GetItemById(id);
}
catch (Exception ex)
{
Label6.Text = "Item Doesnot Exist";
}
if (item != null)
{
item["StuName"] = txt_name.Text;
item["Department"] = txt_dept.Text;
item["Location"] = txt_location.Text;
item["ContactNumber"] = txt_number.Text;
item.Delete();
Label6.Text = "Deleted";
grid();
}
}
}
catch (Exception ex)
{
ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(),
"AlertScript", "(function(){var f = function(){alert('Not Deleted', 370,210);Sys.Application.remove_load(f) ;};Sys.Application.add_load(f) ;})();", true);
}
}
//This will return value from method
protected SPList SpListitems()
{
string strDashListRoot = "http://dev02:2000";
SPSite osite = new SPSite(strDashListRoot);
SPWeb oWeb = osite.OpenWeb();
oWeb.AllowUnsafeUpdates = true;
SPList taskList = oWeb.Lists["Name"];
return taskList;
}
//This clear all textboxes and grid
private void clearcontrols()
{
txt_name.Text = string.Empty;
txt_dept.Text = string.Empty;
txt_location.Text = string.Empty;
txt_number.Text = string.Empty;
txt_Item.Text = string.Empty;
StuList_Grid.Visible = false;
}
//This clear all textboxes
private void clear()
{
txt_name.Text = string.Empty;
txt_dept.Text = string.Empty;
txt_location.Text = string.Empty;
txt_number.Text = string.Empty;
txt_Item.Text = string.Empty;
}
//This to bind the grid
private void grid()
{
StuList_Grid.Visible = true;
SPList taskList = SpListitems();
StuList_Grid.CurrentPageIndex = 0;
//StuList_Grid.CurrentPageIndex = StuList_Grid.PageCount - 1;
DataTable tablelist = taskList.Items.GetDataTable();
StuList_Grid.DataSource = tablelist;
StuList_Grid.DataBind();
}
//This will display latest item first in grid id in descending order
private void Descending()
{
GridSortExpression expression = new GridSortExpression();
expression.FieldName = "ID";
expression.SortOrder = GridSortOrder.Descending;
StuList_Grid.MasterTableView.SortExpressions.AddSortExpression(expression);
}
#endregion
}
}
<
telerik:RadDockLayout
ID
=
"RadDockLayout1"
runat
=
"server"
EnableViewState
=
"false"
>
<
telerik:RadGrid
ID
=
"RadGrid1"
DataSourceID
=
""
runat
=
"server"
AllowPaging
=
"false"
GridLines
=
"None"
PageSize
=
"20"
>
<
MasterTableView
TableLayout
=
"Fixed"
>
<
Columns
>
<
telerik:GridTemplateColumn
DataField
=
"GTC_Column"
>
<
ItemTemplate
>
<
telerik:RadDockZone
ID
=
"RadDockZone1"
runat
=
"server"
FitDocks
=
"true"
EnableViewState
=
"false"
Height
=
"400px"
Width
=
"900px"
Orientation
=
"Horizontal"
ToolTip
=
"Zone1"
></
telerik:RadDockZone
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
</
Columns
>
</
MasterTableView
>
<
ClientSettings
AllowColumnsReorder
=
"true"
ReorderColumnsOnClient
=
"true"
>
<
Resizing
AllowRowResize
=
"True"
EnableRealTimeResize
=
"True"
ResizeGridOnColumnResize
=
"True"
AllowColumnResize
=
"True"
></
Resizing
>
<
ClientEvents
OnGridCreated
=
"onGridCreated"
/>
</
ClientSettings
>
<
HeaderStyle
Width
=
"100px"
/>
</
telerik:RadGrid
>
</
telerik:RadDockLayout
>
<telerik:RadGrid ID=
"_rgPermissions"
runat=
"server"
AutoGenerateColumns=
"False"
HeaderStyle-Font-Bold=
"true"
AllowSorting=
"true"
GridLines=
"None"
Width=
"517px"
Height=
"595px"
Skin=
"Office2007"
OnNeedDataSource=
"_rgPermissions_NeedDataSource"
OnItemDataBound=
"_rgPermissions_ItemDataBound"
Visible=
"false"
>
<AlternatingItemStyle BackColor=
"#f4f5f7"
/>
<GroupingSettings CaseSensitive=
"false"
/>
<MasterTableView>
<Columns>
<telerik:GridBoundColumn UniqueName=
"roleName"
ItemStyle-Font-Size=
"X-Small"
DataField=
"roleName"
HeaderText=
"Role"
>
</telerik:GridBoundColumn>
<telerik:GridTemplateColumn UniqueName=
"SliderPermissions"
HeaderText=
"Permissions"
ItemStyle-HorizontalAlign=
"Center"
HeaderStyle-Width=
"300px"
>
<ItemTemplate>
<telerik:RadSlider runat=
"server"
ID=
"_slPermissions"
Orientation=
"Horizontal"
Width=
"325px"
Height=
"40"
TrackPosition=
"Center"
ItemType=
"Item"
Skin=
"Windows7"
OnClientBeforeValueChange=
"IsItemDisabledOnPermissionsSlider"
>
<Items>
<telerik:RadSliderItem Text=
"None"
Value=
"None"
ToolTip=
"No permissions"
runat=
"server"
>
</telerik:RadSliderItem>
<telerik:RadSliderItem Text=
"View"
Value=
"View"
Enabled=
'<%# Convert.ToString(DataBinder.Eval(Container, "DataItem.View_Static")).Equals("") ? true : !(bool)DataBinder.Eval(Container, "DataItem.View_Static") %>'
ToolTip=
"Role can view folder and its contents"
runat=
"server"
></telerik:RadSliderItem>
<telerik:RadSliderItem Text=
"Add"
Value=
"Add"
Enabled=
'<%# Convert.ToString(DataBinder.Eval(Container, "DataItem.Add_Static")).Equals("") ? true : !(bool)DataBinder.Eval(Container, "DataItem.Add_Static") %>'
ToolTip=
"Role can upload files to folder or create new folders within"
runat=
"server"
>
</telerik:RadSliderItem>
<telerik:RadSliderItem Text=
"Edit"
Value=
"Edit"
Enabled=
'<%# Convert.ToString(DataBinder.Eval(Container, "DataItem.Edit_Static")).Equals("") ? true : !(bool)DataBinder.Eval(Container, "DataItem.Edit_Static") %>'
ToolTip=
"Role can edit folder and its contents"
runat=
"server"
></telerik:RadSliderItem>
<telerik:RadSliderItem Text=
'Delete'
Value=
"Delete"
Enabled=
'<%# Convert.ToString(DataBinder.Eval(Container, "DataItem.Delete_Static")).Equals("") ? true : !(bool)DataBinder.Eval(Container, "DataItem.Delete_Static") %>'
ToolTip=
"Role can delete folder and its contents"
runat=
"server"
></telerik:RadSliderItem>
</Items>
</telerik:RadSlider>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridBoundColumn DataField=
"View_Static"
Visible=
"false"
UniqueName=
"View_Static"
>
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField=
"Add_Static"
Visible=
"false"
UniqueName=
"Add_Static"
>
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField=
"Edit_Static"
Visible=
"false"
UniqueName=
"Edit_Static"
>
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField=
"Delete_Static"
Visible=
"false"
UniqueName=
"Delete_Static"
>
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName=
"roleID"
Visible=
"false"
DataField=
"roleID"
AllowSorting=
"true"
>
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName=
"parentMasterID"
DataField=
"parentMasterID"
Visible=
"false"
AllowSorting=
"true"
>
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField=
"FolderPermissionsID"
Visible=
"false"
UniqueName=
"FolderPermissionsID"
>
</telerik:GridBoundColumn>
</Columns>
</MasterTableView>
<HeaderStyle BorderColor=
"DarkGray"
BorderStyle=
"Solid"
BorderWidth=
"1px"
/>
</telerik:RadGrid>
<telerik:RadCodeBlock ID=
"_rcb"
runat=
"server"
>
<script type=
"text/javascript"
>
function IsItemDisabledOnPermissionsSlider(sender, args) {
if
(!sender.get_items()[args.get_newValue()].get_enabled())
args.set_cancel(
true
);
}
</script>
</telerik:RadCodeBlock>
function SavingChanges() {
var hdn = document.getElementById('<%=hdnIsModified.ClientID %>');
if (hdn) {
hdn.value = 'true';
}
}
function ClosePage() {
var oModifications = document.getElementById('<%=hdnIsModified.ClientID %>');
if (oModifications.value.toLowerCase() == "true") {
GetRadWindow().close('reload');
} else {
GetRadWindow().close();
}
}
function onBeforeWindowClose(oWinow, args) {
function callbckFunction(confirmResult) {
if (confirmResult) {// confirmResult == true
// Close this RadWindow
// First remove the handler in order to avoid recursion
oWinow.remove_beforeClose(onBeforeWindowClose);
oWinow.close();
// Reattach the handles after the window is closed.
// RECOMMENDATION: If the DestroyOnClose="true" property is set in in the RadWindow's declaration,
// then remove this line of the code:
oWinow.add_beforeClose(onBeforeWindowClose);
}
}
// Close the window: If modifications exist, reload parent grid by passing argument
var oModifications = document.getElementById('<%=hdnIsModified.ClientID %>');
if (oModifications.value.toLowerCase() != "true") {
// Cancel closing
args.set_cancel(true);
// Show a rad confirmation dialog
var sMsg = "Are you sure you want to cancel " + document.getElementById('<%=Mode.ClientID %>').value.toLowerCase() + "ing" + " the new requirement?";
radconfirm(sMsg, callbckFunction, 400, 150, null, "Confirm");
}
}
function GetRadWindow() {
var oWindow = null;
if (window.radWindow)
oWindow = window.radWindow;
else if (window.frameElement.radWindow)
oWindow = window.frameElement.radWindow;
return oWindow;
}
function pageLoad() {
// Get the RadWindoiw object that contains this page
var oWindow = GetRadWindow();
// Attach RadWindow's OnClientBeforeClose handler
oWindow.add_beforeClose(onBeforeWindowClose);
}
function pageUnload() {
// Get the RadWindoiw object that contains this page
var oWindow = GetRadWindow();
// NOTE! If the DestroyOnClose="true" is set in the RadWindow's declaration,
// then the oWindow object will be 'null'.
if (oWindow) {
// Detach RadWindow's OnClientBeforeClose handler
oWindow.remove_beforeClose(onBeforeWindowClose);
}
}
<
asp:Button
ID
=
"Save"
runat
=
"server"
Text
=
"Save"
onclick
=
"Save_Click"
OnClientClick
=
"SavingChanges();"
/>
<
input
id
=
"butCancel"
type
=
"button"
value
=
"Cancel"
onclick
=
"ClosePage();"
/>
<
div
style
=
"margin-left: 15px; margin-right: 10px; margin-top: 8px; margin-bottom: 8px"
>
<
hr
/>
<
telerik:RadAjaxPanel
ID
=
"RadAjaxPanel1"
runat
=
"server"
LoadingPanelID
=
"RadAjaxLoadingPanel1"
>
<
div
ID
=
"DataEntryArea"
class
=
"span-22 last"
runat
=
"server"
>
</
div
>
</
telerik:RadAjaxPanel
>
<
hr
style
=
"margin:0.5em 0 0 0"
/>
</
div
>
<
telerik:GridBoundColumn
DataField
=
"IC01Name"
FilterControlWidth
=
"40px"
HeaderText
=
"IC01 Name"
SortExpression
=
"IC01Name"
UniqueName
=
"IC01Name"
>
<
HeaderStyle
Width
=
"70px"
/>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"IC01 Name"
FilterControlWidth
=
"40px"
HeaderText
=
"IC01 Name"
SortExpression
=
"IC01 Name"
UniqueName
=
"IC01 Name"
>
<
HeaderStyle
Width
=
"70px"
/>
</
telerik:GridBoundColumn
>
<
SortExpressions
>
<
telerik:GridSortExpression
FieldName
=
"OriginCity"
/>
</
SortExpressions
>
<
telerik:GridCalculatedColumn
UniqueName
=
"Origin"
HeaderText
=
"Origin"
AutoPostBackOnFilter
=
"true"
SortExpression
=
"{0} , {1}"
DataFields
=
"OriginCity, OriginState"
Expression
=
'{0} + " " + {1}'
>
<
HeaderStyle
HorizontalAlign
=
"Left"
VerticalAlign
=
"Bottom"
/>
<
ItemStyle
HorizontalAlign
=
"Left"
/>
</
telerik:GridCalculatedColumn
>