2013-09-23 9 views
0

이전에 읽기 전용이었던 페이지에 컨트롤을 추가하려고합니다. 환경은 다음과 같습니다오류 : 이름이 현재 컨텍스트에 존재하지 않습니다. (Webpart, C#, Visual Studio, SharePoint 2010)

  • 셰어 비주얼 스튜디오 2010
  • 이 기능이는 WebPart에에서 개발 2010 솔루션
  • (AceAllocation30.cs)
  • 코드는 C#을 여기

내가 추가 한 코드는 다음과 같습니다.

sb.Append("  <td width=\"75%\">"); lc3 = new LiteralControl(sb.ToString()); Controls.Add(lc3); TextBox JDHFTxt = new TextBox(); JDHFTxt.ID = "txtJDHF"; JDHFTxt.Enabled = true; JDHFTxt.Value = ConvertToAllocation(DrACE["SPRAmount"].ToString()); Controls.Add(JDHFTxt); sb = new StringBuilder(); 
sb.Append("</td>"); 

위의 추가 코드이 코드 교체 : 더 완전한 참고로

sb.Append("    <td class=\"rowText\" width=\"75%\">" + ConvertToAllocation(DrACE["SPRAmount"].ToString()) + "</td>"); 

을, 위의 전체 원래 segement은 이것이다 :

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>"); 

을하지만 배포 할 때 다음 오류가 발생합니다.

  • 오류 35; 'System.Web.UI.WebControls.TextBox'에 'Value'에 대한 정의가없고 'System.Web.UI.WebControls.TextBox'형식의 첫 번째 인수를 허용하는 'Value'는 이 될 수 있습니다. (using 지시문이나 어셈블리 참조가 누락 되었습니까?)

  • 오류 32; 'lc3'이름이 현재 컨텍스트에 존재하지 않습니다.

  • 오류 33; 이름 'LC3'는 현재 컨텍스트 여기

전체 페이지 코드에 존재하지 않습니다 여기

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); 
     } 
    } 
} 

가 그리고하면 페이지의 모습의 모형이다 : enter image description here

답변

0

문제는 필자가 리터럴 컨트롤을 사용하기 전에 추가하지 않았기 때문입니다. 필드와 컨트롤이있는 테이블을 만들기 바로 전에 추가했습니다.

LiteralControl lc3 = new LiteralControl();