Domanda

Basically the situation is as follows:

  • The below image is a mockup of what the actual webpage on the site looks like.
  • Programming is declarative and utilizes C#, SQL Server 2008. Visual Studios 2010 (SharePoint solution project), SharePoint 2010, Webparts, JavaScript, and jQuery.
  • Currently, only clicking the edit buttons (Edit Allocations, Add New Allocation) allows you to edit these items – a user goes to another form with enabled controls (which is an aspx form), makes the change, and saves.
  • However, each item needs to be editable from this page. So each item will need an Edit button that enables the control, a Save Button, and a Cancel button.
  • Allocation Available needs to be a yes/no radio button & needs to be editable from this page.
  • SPR/JDHF Allotment needs to be a textbox & needs to be editable from this page.
  • SPR Source needs to be a dropdown & pull from Lookup Management in the database & needs to be editable from this page.
  • Allocation Comments needs to be a multiline textbox & needs to be editable from this page.
  • All items need to be editable from the page, so each one needs to have a edit, save and cancel button, one on each line for each item
  • Each of these tabs (Manage ACE, Summary View, etc is actually a webpart)

I haven't the first clue how to go about doing this. If anyone could point me in the right direction, perhaps walking me through how to add just one of these controls and I can scaffold off of that learning to do the rest I would be very grateful. Thank you.

Site Mockup: enter image description here

Page Code:

using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
//Data Controls
using System.Runtime.InteropServices;
using System.Data;
using System.Collections.Specialized;
using System.Data.SqlClient;
using IDE_Utility.DBConnection;
using IDE_Utility.ErrorLogging;
using System.Text;


namespace GIK30.ACEAllocation30
{
    [ToolboxItemAttribute(false)]
    public class ACEAllocation30 : WebPart
    {
        private bool _error = false;
        private string _myProperty = null;
        private Label m_lblMsg;
        private Button m_NewAllocation_Button;
        private HttpResponse Response = HttpContext.Current.Response;

        [Personalizable(PersonalizationScope.Shared)]
        [WebBrowsable(true)]
        [System.ComponentModel.Category("My Property Group")]
        [WebDisplayName("MyProperty")]
        [WebDescription("Meaningless Property")]
        public string MyProperty
        {
            get
            {
                if (_myProperty == null)
                {
                    _myProperty = "";
                }
                return _myProperty;
            }
            set
            {                                                                                                              
                _myProperty = value;
            }
        }

        public ACEAllocation30()
        {
            this.ExportMode = WebPartExportMode.All;
        }

        /// <summary>
        /// Create all your controls here for rendering.
        /// Try to avoid using the RenderWebPart() method.
        /// </summary>
        protected override void CreateChildControls()
        {
            if (!_error)
            {
                SPSite site = SPContext.Current.Site;
                DataSet DsAllocation = new DataSet();
                DataView DvAllocation = null;
                DataSet DsACE = new DataSet();
                DataRow DrACE;
                int ACEID = 0;

                if (site != null)
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        try
                        {
                            int.TryParse(Page.Request["ACEID"], out ACEID);
                            int UserID = GIK20_CodeLibrary.GetUserID(SPContext.Current.Web);
                            StringCollection Access = GIK20_CodeLibrary.GetUserAccessForACE(UserID, ACEID);
                            bool IsACEAdmin = GIK20_CodeLibrary.IsUserACEAdmin(Access);
                            bool IsContracts = GIK20_CodeLibrary.IsUserAllocationSpecialist(Access);

                            // Make sure the ACE exists first
                            Boolean IsACE = false;
                            SqlParameter sqlParamACEID = new SqlParameter();
                            sqlParamACEID.ParameterName = "@aceid";
                            sqlParamACEID.DbType = DbType.Int32;
                            sqlParamACEID.Value = ACEID;

                            SqlParameter[] sqlParams = new SqlParameter[]
                            {
                                sqlParamACEID
                            };
                            try
                            {
                                DsACE = DBConnection.GetDataSet("getAceInfo", CommandType.StoredProcedure, sqlParams);
                            }
                            catch (Exception ex)
                            {
                                HandleException(ex);
                                IDEErrLogging.LogError(new IDEException("ACE Allocation: Validate ACE: Error on Stored Procedure: getAceInfo", ex), true, false, SPContext.Current.Web);
                            }
                            if (DsACE != null)
                            {
                                if (DsACE.Tables[0].Rows.Count == 1)
                                    IsACE = true;
                            }

                            if (IsACE)
                            {
                                base.CreateChildControls();
                                DrACE = DsACE.Tables[0].Rows[0];

                                //strSQL = "select * from ACE_Allocation where ACEID = " + ACEID.ToString();
                                try
                                {
                                    sqlParamACEID = new SqlParameter();
                                    sqlParamACEID.ParameterName = "@aceid";
                                    sqlParamACEID.DbType = DbType.Int32;
                                    sqlParamACEID.Value = ACEID;

                                    sqlParams = new SqlParameter[]
                                    {
                                        sqlParamACEID
                                    };
                                    DsAllocation = DBConnection.GetDataSet("getACeAllocation", CommandType.StoredProcedure, sqlParams);
                                    DvAllocation = DsAllocation.Tables[0].DefaultView;
                                    DvAllocation.Sort = "FY, AllocationType";
                                }
                                catch (Exception ex)
                                {
                                    HandleException(ex);
                                    IDEErrLogging.LogError(new IDEException("ACE Allocation: Error on ACE Allocation Stored Procedure: getACeAllocation", ex), true, false, SPContext.Current.Web);
                                }

                                // Check to see if edit controls are enabled
                                Boolean enableStatus = false;
                                if (IsACEAdmin || IsContracts)
                                    enableStatus = true;

                                //enableStatus = GIK20_CodeLibrary.CheckUserInGroup(myWeb, statusArray);

                                string AllocationAvail = "No";
                                if (DrACE["AllocationAVailable"].Equals(true))
                                {
                                    AllocationAvail = "Yes";
                                }


                                StringBuilder sb = new StringBuilder();
                                sb.Append("<div class=\"border\" style=\"width:700px\">");
                                sb.Append("  <div class=\"partTitle\" >");
                                sb.Append("     <table cellspacing=\"0\" cellpadding=\"0\" height=\"25px\" width=\"100%\">");
                                sb.Append("         <tr>");
                                sb.Append("             <td class=\"partTitleText\">ACE ALLOCATION</td>");
                                sb.Append("         </tr>");
                                sb.Append("     </table>");
                                sb.Append("  </div>");
                                sb.Append("  <div class=\"columnHeader\">");
                                sb.Append("     <table cellspacing=\"0\" cellpadding=\"0\" height=\"25px\" width=\"100%\">");
                                sb.Append("         <tr>");
                                sb.Append("             <td class=\"columnHeaderText\" style=\"margin-top:5px;\">Allocation Information</td>");
                                sb.Append("         </tr>");
                                sb.Append("     </table>");
                                sb.Append("  </div>");
                                sb.Append("  <div class=\"rows\">");
                                sb.Append("     <table cellspacing=\"0\" cellpadding=\"0\" width=\"100%\">");
                                sb.Append("         <tr class=\"row1\">");
                                sb.Append("             <td class=\"rowTextLeft\" width=\"25%\">Allocation Available:</td>");
                                sb.Append("             <td class=\"rowText\" width=\"75%\">" + AllocationAvail + "</td>");
                                sb.Append("         </tr>");
                                sb.Append("         <tr class=\"row2\">");
                                sb.Append("             <td class=\"rowTextLeft\" width=\"25%\">SPR/JDHF Allotment:</td>");
                                sb.Append("             <td class=\"rowText\" width=\"75%\">" + ConvertToAllocation(DrACE["SPRAmount"].ToString()) + "</td>");
                                sb.Append("         </tr>");
                                sb.Append("         <tr class=\"row1\">");
                                sb.Append("             <td class=\"rowTextLeft\" width=\"25%\">SPR Source:</td>");
                                sb.Append("             <td class=\"rowText\" width=\"75%\">" + DrACE["SPRSource"] + "</td>");
                                sb.Append("         </tr>");
                                //sb.Append("         <tr class=\"row2\">");
                                //sb.Append("             <td class=\"rowTextLeft\" width=\"25%\">TEV:</td>");
                                //sb.Append("             <td class=\"rowText\" width=\"75%\">" + ConvertToAllocation(DrACE["EstVal"].ToString()) + "</td>");  //); + DrACE["SPRSource"] + "</td>");
                                //sb.Append("         </tr>");
                                sb.Append("         <tr class=\"row2\">");
                                sb.Append("             <td class=\"rowTextLeft\" width=\"25%\">Allocation Comments:</td>");
                                sb.Append("             <td class=\"rowText\" width=\"75%\">" + DrACE["AllocationComments"] + "</td>");
                                sb.Append("         </tr>");
                                sb.Append("     </table>");
                                sb.Append("  </div>");
                                sb.Append("  <div class=\"columnHeader\">");
                                sb.Append("     <table cellspacing=\"0\" cellpadding=\"0\" height=\"25px\" width=\"100%\">");
                                sb.Append("         <tr>");
                                sb.Append("             <td class=\"rowTextTitle\" width=\"21%\">Type</td>");
                                sb.Append("             <td class=\"rowTextTitle\" width=\"20%\">Source</td>");
                                sb.Append("             <td class=\"rowTextTitle\" width=\"20%\">FY</td>");
                                sb.Append("             <td class=\"rowTextTitle\" width=\"20%\">$ Amount</td>");
                                sb.Append("             <td width=\"19%\"></td>");
                                sb.Append("         </tr>");
                                sb.Append("     </table>");
                                sb.Append("  </div>");
                                sb.Append("  <div class=\"rows\">");
                                sb.Append("     <table cellspacing=\"0\" cellpadding=\"0\" width=\"100%\">");

                                if (DvAllocation != null)
                                {
                                    Boolean row1 = true;
                                    int i = 1;
                                    LiteralControl lc2 = new LiteralControl();

                                    foreach (DataRowView DvAllocationRow in DvAllocation)
                                    {
                                        if (row1)
                                        {
                                            sb.Append("         <tr class=\"row1\">");
                                            row1 = false;
                                        }
                                        else
                                        {
                                            sb.Append("         <tr class=\"row2\">");
                                            row1 = true;
                                        }


                                        sb.Append("             <td class=\"rowText\" width=\"21%\">" + DvAllocationRow["AllocationType"].ToString() + "</td>");
                                        sb.Append("             <td class=\"rowText\" width=\"20%\">" + DvAllocationRow["AllocationSourceName"].ToString() + "</td>");
                                        sb.Append("             <td class=\"rowText\" width=\"20%\">" + DvAllocationRow["FYTxt"].ToString() + "</td>");
                                        sb.Append("             <td class=\"rowText\" width=\"20%\">" + ConvertToAllocation(DvAllocationRow["Amount"].ToString()) + "</td>");
                                        string querystring = "?ACEID=" + DvAllocationRow["ACEID"].ToString() + "&ACEAllocationID=" + DvAllocationRow["ACE_AllocationID"].ToString();
                                        if (enableStatus)
                                        {
                                            m_NewAllocation_Button = new Button();
                                            m_NewAllocation_Button.Text = "Edit Allocation";
                                            //m_NewAllocation_Button.Style = "font-size:8pt;font-family:Verdana,sans-serif";
                                            //m_NewAllocation_Button.Width = 80;
                                            //m_NewAllocation_Button.Height = 21;
                                            m_NewAllocation_Button.CssClass = "plainButton";
                                            m_NewAllocation_Button.ID = "NewAllocationButton" + i;
                                            m_NewAllocation_Button.Attributes.Add("OnClick", "window.open('../_layouts/GIK30/EditAllocation.aspx" + querystring + "');");
                                            //string[] statusArray = new string[] { "Owner", "SiteAdmin" };
                                            m_NewAllocation_Button.Enabled = enableStatus;
                                            //m_NewAllocation_Button.Visible = enableStatus;

                                            sb.Append("             <td width=\"19%\" align=\"right\" style=\"padding-right:20px\">");
                                            lc2 = new LiteralControl(sb.ToString());
                                            Controls.Add(lc2);
                                            Controls.Add(m_NewAllocation_Button);
                                            sb = new StringBuilder();
                                            sb.Append("</td>");
                                        }
                                        else
                                            sb.Append("             <td width=\"19%\"></td>");
                                        //sb.Append("             <td width=\"19%\"><input TYPE=\"button\" VALUE=\"Edit Allocation\" style=\"font-size:8pt;font-family:Verdana,sans-serif\" />");
                                        sb.Append("             </td>");
                                        sb.Append("         </tr>");
                                        i++;
                                    }
                                }
                                else
                                {
                                    sb.Append("     <tr class=\"row1\"><td class=\"rowText\" width=\"100%\">Error Reading from Database</td></tr>");
                                }
                                sb.Append("     </table>");
                                sb.Append("  </div>");
                                sb.Append("  <table cellspacing=\"0\" cellpadding=\"0\" style=\"margin-left:9px; margin-top:1px; margin-right:9px\">");
                                sb.Append("     <tr class=\"total\">");
                                sb.Append("         <td width=\"555px\" style=\"vertical-align:middle\">EV on Allotment: " + ConvertToAllocation(DrACE["EstVa"].ToString()) + "</td>");
                                sb.Append("         <td align=\"right\" style=\"padding-right:5px\">");
                                LiteralControl lc = new LiteralControl(sb.ToString());
                                Controls.Add(lc);

                                m_NewAllocation_Button = new Button();
                                m_NewAllocation_Button.Text = "Add New Allocation";
                                //m_NewAllocation_Button.Style = "font-size:8pt;font-family:Verdana,sans-serif";
                                //m_NewAllocation_Button.Width = 80;
                                //m_NewAllocation_Button.Height = 21;
                                m_NewAllocation_Button.CssClass = "plainButton";
                                m_NewAllocation_Button.ID = "NewAllocationButton";
                                m_NewAllocation_Button.Attributes.Add("OnClick", "window.open('../_layouts/GIK30/EditAllocation.aspx?ACEID=" + ACEID + "');");
                                //string[] statusArray = new string[] { "Owner", "SiteAdmin" };
                                m_NewAllocation_Button.Enabled = enableStatus;
                                //m_NewAllocation_Button.Visible = enableStatus;
                                Controls.Add(m_NewAllocation_Button);

                                sb = new StringBuilder();
                                sb.Append("</td>");
                                sb.Append("     </tr>");
                                sb.Append("  </table>");
                                sb.Append("</div>");
                                lc = new LiteralControl(sb.ToString());
                                Controls.Add(lc);
                            }
                        }
                        catch (Exception ex)
                        {
                            HandleException(ex);
                            IDEErrLogging.LogError(new IDEException("ACE Allocation: Error on ACE: " + ACEID.ToString(), ex), true, false, SPContext.Current.Web);
                        }
                    }
                }
            }
        }

        /// <summary>
        /// Ensures that the CreateChildControls() is called before events.
        /// Use CreateChildControls() to create your controls.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnLoad(EventArgs e)
        {
            if (!_error)
            {
                try
                {
                    base.OnLoad(e);
                    this.EnsureChildControls();
                    // Your code here...
                }
                catch (Exception ex)
                {
                    HandleException(ex);
                }
            }
        }

        /// <summary>
        /// Clear all child controls and add an error message for display.
        /// </summary>
        /// <param name="ex"></param>
        private void HandleException(Exception ex)
        {
            this._error = true;
            this.Controls.Clear();
            this.Controls.Add(new LiteralControl(ex.Message));
        }

        protected void m_NewAllocation_Button_Click(object sender, EventArgs e)
        {
            Page.Response.Redirect("EditAllocation.aspx?ACEID=" + Page.Request["ACEID"]);
        }

        private string ConvertToAllocation(string stramount)
        {
            // Convert the real number to a $ format
            double amount = 0.0;
            if (!String.IsNullOrEmpty(stramount))
                amount = Convert.ToDouble(stramount);
            return string.Format("{0:C}", amount);
        }
    }
}
È stato utile?

Soluzione

The solution I arrived at is:

First I added a new literal control before the table code (where I had the fields and wanted to add the controls):

LiteralControl lc3 = new LiteralControl();

Then, I included the LC in the table where I wanted to change the read only value to a control, so for example:

   sb.Append("             <td class=\"rowTextLeft\" width=\"25%\">SPR/JDHF Allotment:</td>");
   sb.Append("             <td class = \"rowText\" td width=\"75%\">"); 
                                                   lc3 = new LiteralControl(sb.ToString()); 
                                                   Controls.Add(lc3); 
                                                   TextBox JDHFTxt = new TextBox(); 
                                                   JDHFTxt.ID = "txtJDHF"; 
                                                   JDHFTxt.Enabled = false; 
                                                   JDHFTxt.Value = ConvertToAllocation(DrACE["SPRAllotment"].ToString()); 
                                                   Controls.Add(JDHFTxt); 
                                                   sb = new StringBuilder();
   sb.Append("</td>");
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top