我正在尝试在沙盒解决方案中创建可视webpart。我在ascx页面中添加了一个名为ProjectClient的下拉列表,并编写了一个函数来绑定代码隐藏中的下拉列表。但我得到的错误是“名称'ProjectClient'在当前上下文中不存在”。我检查了ascx.g.cs页面,控件ID在那里是正确的。请帮我解决这个问题。
ascx页面:
<div class="col-lg-1">
<asp:Label ID="pClient" runat="server" Text='<%#Eval("Client") %>' />
<asp:DropDownList ID="ProjectClient" runat="server" CssClass="ddclient" Visible="false"></asp:DropDownList>
</div>
文件后面的代码:
public void BindDropDown()
{
ProjectClient.Items.Clear();
if (listToBind != null)
{
ProjectClient.DataSource = listToBind;
ProjectClient.DataTextField = textField;
ProjectClient.DataValueField = valueField;
ProjectClient.DataBind();
}
ProjectClient.Items.Insert(0, new ListItem("-Select-", ""));
}
ascx.g.cs页面:
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never)]
[GeneratedCodeAttribute("Microsoft.VisualStudio.SharePoint.ProjectExtensions.CodeGenerators.SharePointWebP" +
"artCodeGenerator", "12.0.0.0")]
private global::System.Web.UI.WebControls.DropDownList @__BuildControl__control7() {
global::System.Web.UI.WebControls.DropDownList @__ctrl;
@__ctrl = new global::System.Web.UI.WebControls.DropDownList();
@__ctrl.TemplateControl = this;
@__ctrl.ApplyStyleSheetSkin(this.Page);
@__ctrl.ID = "ProjectClient";
@__ctrl.CssClass = "ddclient";
@__ctrl.Visible = false;
return @__ctrl;
}