Monday, 4 June 2012

ASCX.CS(.ascx.cs)

STEP 1: Create a VisualWebPart like PropellerStudioReadMore

STEP 2: Write a coding in PropellerStudioReadMoreUserControl.ascx.cs 


STEP 3:

using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using VCSB.INTRANET.BLL;
using System.Collections;
using System.Data;
using Microsoft.SharePoint.WebControls;
using System.Collections.Generic;
using Microsoft.SharePoint;
using System.Linq;

namespace VCSB01.INTRANET.WebPartDetailsPage.PropellerStudioReadMore
{
    public partial class PropellerStudioReadMoreUserControl : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (IsSuperAdmin || IsAdmin || IsManager)
                {
                    imgbtnAdd.Visible = true;
                    imgbtnEdit.Visible = true;
                    imgbtnDelete.Visible = true;
                }
                else
                {
                    imgbtnAdd.Visible = false;
                    imgbtnEdit.Visible = false;
                    imgbtnDelete.Visible = false;
                }
                BindPropellerstudioData();
            }
        }
        private void BindPropellerstudioData()
        {
           
            PropellerStudioBL objpropData = new PropellerStudioBL();
            grdPropellerDetails.DataSource = objpropData.GetAllListItem();
            grdPropellerDetails.DataBind();
            Session["TaskTable"] = objpropData.GetAllListItem();
        }
       
        public void clear()
        {
            txtPropellerTitle.Text = string.Empty;
            txtPropellerDescription.Text = string.Empty;
        }

        protected void btnPropellerSubmit_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(txtPropellerTitle.Text) && !string.IsNullOrEmpty(txtPropellerDescription.Text))
            {
                PropellerStudioBL propellerStudioBL = new PropellerStudioBL(txtPropellerTitle.Text, txtPropellerDescription.Text, flpPropeller);
                if (propellerStudioBL.insert())
                {
                    BindPropellerstudioData();
                }              
            }

            clear();
        }

        protected void imgbtnDelete_Click1(object sender, ImageClickEventArgs e)
        {
            foreach (GridViewRow di in grdPropellerDetails.Rows)
            {
                CheckBox chkBx = (CheckBox)di.FindControl("chkSelect");

                HiddenField htnobj = (HiddenField)di.FindControl("hdfPropeller");
                if (chkBx.Checked)
                {
                    PropellerStudioBL propellerStudioBL = new PropellerStudioBL(Convert.ToInt32(htnobj.Value));
                    if (propellerStudioBL.delete())
                    {
                        //
                    }
                }
            }
            BindPropellerstudioData();
        }

        protected void imgbtnEdit_Click1(object sender, ImageClickEventArgs e)
        {
            btnPropellerSubmit.Visible = false;
            DataTable dt = new DataTable();
            foreach (GridViewRow di in grdPropellerDetails.Rows)
            {
                CheckBox chkBx = (CheckBox)di.FindControl("chkSelect");

                HiddenField htnobj = (HiddenField)di.FindControl("hdfPropeller");
                if (chkBx.Checked)
                {
                    PropellerStudioBL propellerstudioSingleRow = new PropellerStudioBL(Convert.ToInt32(htnobj.Value));
                    dt = propellerstudioSingleRow.GetSingleRowListItem();
                    txtPropellerTitle.Focus();
                    txtPropellerTitle.Text = Convert.ToString(dt.Rows[0]["Title"]);
                    txtPropellerDescription.Text = Convert.ToString(dt.Rows[0]["Description"]);
                    string path = Convert.ToString(dt.Rows[0]["FileImage"]);

                }
            }
            mpePropellerEdit.Show();
        }

        protected void btnPropellerUpdate_Click1(object sender, EventArgs e)
        {
            System.Diagnostics.Debugger.Launch();
            foreach (GridViewRow di in grdPropellerDetails.Rows)
            {
                CheckBox chkBx = (CheckBox)di.FindControl("chkSelect");

                HiddenField htnobj = (HiddenField)di.FindControl("hdfPropeller");
                if (chkBx.Checked)
                {
                    PropellerStudioBL propellerStudioBL = new PropellerStudioBL(Convert.ToInt32(htnobj.Value), txtPropellerTitle.Text, txtPropellerDescription.Text, flpPropeller);
                    if (propellerStudioBL.update())
                    {
                        BindPropellerstudioData();
                    }


                }
            }
        }

        protected void grdPropellerDetails_Sorting(object sender, GridViewSortEventArgs e)
        {

            //Retrieve the table from the session object.
            DataTable dt = Session["TaskTable"] as DataTable;

            if (dt != null)
            {

                //Sort the data.
                dt.DefaultView.Sort = e.SortExpression + " " + GetSortDirection(e.SortExpression);
                grdPropellerDetails.DataSource = Session["TaskTable"];
                grdPropellerDetails.DataBind();
            }

        }

        private string GetSortDirection(string column)
        {

            // By default, set the sort direction to ascending.
            string sortDirection = "ASC";

            // Retrieve the last column that was sorted.
            string sortExpression = ViewState["SortExpression"] as string;

            if (sortExpression != null)
            {
                // Check if the same column is being sorted.
                // Otherwise, the default value can be returned.
                if (sortExpression == column)
                {
                    string lastDirection = ViewState["SortDirection"] as string;
                    if ((lastDirection != null) && (lastDirection == "ASC"))
                    {
                        sortDirection = "DESC";
                    }
                }
            }

            // Save new values in ViewState.
            ViewState["SortDirection"] = sortDirection;
            ViewState["SortExpression"] = column;

            return sortDirection;
        }

       
    }
}

       




 

No comments:

Post a Comment

SharePoint online - Get List-item attachments and Display to div

Step 1 : Create a List ex: TestList and attach few images Step 2 : Copy and Pastet the below coding in App.js var  Items =  null ; ...