如何修复名称' '在当前上下文中不存在

时间:2014-03-13 12:52:42

标签: c# asp.net sharepoint

你好,为什么我部署我的项目时给了我

  

这个名字' '在当前情境中不存在..

此错误出现在ascx.cs页面中。但此名称存在于ascx页面中。

来自ascx.cs页面的代码:

using System;
using System.ComponentModel;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using System.Text;
using System.Data;
using System.Collections.Generic;
using System.Web.UI.WebControls;
using Microsoft.SharePoint.Linq;
using System.Linq;
using System.Web;


namespace Safety360.SafetyDrills.WebParts.InspectionManagement1
{
    [ToolboxItemAttribute(false)]
    public partial class InspectionManagement1 : WebPart
    {
       [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Assert, UnmanagedCode = true)]
        public InspectionManagement1()
        {
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            InitializeControl();
        }


        private string GetBoolean(string value)
        {
            if (value.ToLower() == "true")
            {
                return "Yes";
            }
            else
            {
                return "No";
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                grdsettings.DataSource = GetListValue();
                grdsettings.DataBind();
                DataTable dt = new DataTable();
                dt = GetListValue();
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    RadioButtonList rblsettings = (RadioButtonList)grdsettings.Rows[i].FindControl("rblsettings");


                    rblsettings.SelectedValue = GetBoolean(dt.Rows[i]["Settings Value"].ToString());
                }

            }

        }

        DataTable GetListValue()
        {


            SPSite oSiteCollection = SPContext.Current.Site;
            SPWeb oWeb = oSiteCollection.OpenWeb();
            SPList oSPList = oWeb.Lists["Inspection Management"];
            SPListItemCollection oSPListItemCollection = oSPList.Items;
            DataTable dt = new DataTable();

            try
            {
                dt.Columns.Add("ID", typeof(int));
                dt.Columns.Add("Settings Name", typeof(String));
                dt.Columns.Add("Settings Value", typeof(string));
                DataRow dataRow;
                foreach (SPListItem oSplistItem in oSPListItemCollection)
                {
                    dataRow = dt.Rows.Add();
                    dataRow["ID"] = oSplistItem["ID"];
                    dataRow["Settings Name"] = oSplistItem["Settings Name"].ToString();
                    dataRow["Settings Value"] = oSplistItem["Settings Value"].ToString();
                }
                return dt;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Managers Approval" + ex.Message.ToString());
                return dt;
            }


        } 

        private int GetIntBoolean(string value)
        {
            if (value.ToLower() == "yes")
                return 1;
            else
                return 0;
        }
        private void SaveSettings()
        {
            string value = String.Empty;
            foreach (GridViewRow row in grdsettings.Rows)
            {
                RadioButtonList rblsettings = (RadioButtonList)row.FindControl("rblsettings");
                if (rblsettings != null)
                {
                    value = rblsettings.SelectedValue;
                    int rowindex = row.RowIndex;
                    int SettingsId = Convert.ToInt32(grdsettings.DataKeys[rowindex].Values[0].ToString());
                    SPListItem item = SPContext.Current.Web.Lists["Inspection Management"].Items.GetItemById(SettingsId);
                    item["Settings Value"] = GetIntBoolean(value);
                    item.Update();
                }
            }
            grdsettings.DataSource = GetListValue();
            grdsettings.DataBind();
            DataTable dt = new DataTable();
            dt = GetListValue();
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                RadioButtonList rblsettings = (RadioButtonList)grdsettings.Rows[i].FindControl("rblsettings");
                rblsettings.SelectedValue = GetBoolean(dt.Rows[i]["Settings Value"].ToString());
            }
         }

        protected void btnsave_Click(object sender, EventArgs e)
        {
            SaveSettings();
        }

        protected void btncancle_Click(object sender, EventArgs e)
        {

        }
    }
}

此代码来自ascx页面:

<%@ 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="InspectionManagement2.ascx.cs" Inherits="Safety360.SafetyDrills.WebParts.InspectionManagement2.InspectionManagement2" %>

<link rel="Stylesheet" type="text/css" href="../_layouts/CSS/formsA.css" media="screen" />
 <table style="width:100%;">
            <tr>
                <td style="width:25%; height:2px;">

                </td>
            </tr>
            <tr>
                <td style="width:50%; vertical-align:middle; text-align:center; height:25px; font-weight: bold; font-size: large; color: #000066;">
                    <asp:Literal ID="ltrlMainTitle" runat="server"
                        Text="Inspection Management General Settings Page"></asp:Literal>
                </td>
            </tr>
            <tr>
                <td style="width:25%; height:2px;"></td>
            </tr>
        </table>
 <table style="width:100%;">
            <tr>
                <td class="HeaderRow">
                    <asp:Literal ID="ltrlSubTitle" runat="server"
                        Text="Settings"></asp:Literal>
                </td>
            </tr>
        </table>
 <table border="0" cellspacing="0" width="100%">

                    <asp:GridView ID="grdsettings" Width="100%" DataKeyNames="ID"
                AutoGenerateColumns="False" runat="server" EnableModelValidation="True"  CellPadding="4" ForeColor="#333333" GridLines="None">
                        <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                            <Columns>
                                <asp:BoundField DataField="ID" HeaderText="ID" SortExpression="ID"  />
                                <asp:BoundField DataField="Settings Name" HeaderText="Settings Name" SortExpression="Settings Name"  />                                  
                                <asp:TemplateField>

                    <ItemTemplate>

                                 <asp:RadioButtonList ID="rblsettings" runat="server" RepeatDirection="Horizontal" ForeColor="Black" CommandArgument='<%# ((GridViewRow) Container).RowIndex %>' >
                                     <asp:ListItem Value="Yes">Yes</asp:ListItem>
                                     <asp:ListItem Value="No">No</asp:ListItem>
                                 </asp:RadioButtonList>
                        </ItemTemplate>
                                     </asp:TemplateField>
                                </Columns>
                         <EditRowStyle BackColor="#999999" />
                <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" HorizontalAlign="Left"/>
                <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" HorizontalAlign="Left"/>
                <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="left" />
                <RowStyle BackColor="#F7F6F3" ForeColor="#333333" HorizontalAlign="left" />
                <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                        </asp:GridView>


                </table>
<table style="width: 100%; text-align: right;">
    <tr>
        <td>
            <table>
                <tr>
                    <td nowrap="true" style="width: 100%" class="ms-formButtons"></td>
                    <td nowrap="nowrap" class="ms-formlabel">
                        <asp:Button ID="btnsave" CausesValidation="true"  runat="server" Text="Save" CssClass="ms-ButtonHeightWidth" OnClick="btnsave_Click" />
                    </td>
                    <td nowrap="nowrap" class="ms-formlabel">
                        <asp:Button ID="btncancle" CausesValidation="true"  runat="server" Text="Cancle" CssClass="ms-ButtonHeightWidth" OnClick="btncancle_Click" />
                    </td>
                </tr>
            </table>
        </td>
    </tr>
</table>

找不到此页面的设计器文件。 我能做什么,如何将设计师文件归还给我的项目?

1 个答案:

答案 0 :(得分:0)

要查找设计器文件,请右键单击项目并选择打开包含文件夹,如果找到目标.ascx文件的.designer.cs文件,则在解决方案资源管理器中转到项目,然后单击“显示所有文件” “在解决方案资源管理器窗口的上部面板中,您会发现设计器文件出现在文件列表中,不透明度较低,右键单击它并按”包含在项目中“。

如果在项目文件夹中没有找到它,只需重新创建页面并复制代码即可。