【发布时间】:2016-01-18 06:10:29
【问题描述】:
当我使用时
protected void GenGridView()
{
var data = project.ObtainDataDescJSON();
Title = "show";
for (int rowCtr = 0; row < data.Num.Count; row++)
{
var buttonField = new ButtonField
{
ButtonType = ButtonType.Button,
Text = "Show",
CommandName = "Display"
};
buttonField.Attributes.Add("data-toggle", "modal");
buttonField.Attributes.Add("data-target", "#myModal");
buttonField.CssClass = "btn btn-info";
ModelNumFieldsGrid.Columns.Add(buttonField);
break;
}
}
在 C# 中定义按钮时出现错误说没有扩展属性和没有扩展 cssClass。
我试过了
[AttributeUsageAttribute(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Method)]
public sealed class ExtensionAttribute : Attribute
和
using System.Runtime.CompilerServices.ExtensionAttribute;
但不起作用。我该如何解决它
我的确切错误
Error 2 'System.Web.UI.WebControls.ButtonField' does not contain a definition for 'Attributes' and no extension method 'Attributes' accepting a first argument of type 'System.Web.UI.WebControls.ButtonField' could be found (are you missing a using directive or an assembly reference?) C:\Users\s0\Documents\Visual Studio 2013\WebSites\Model.aspx.cs 55 25 Pred
Error 7 'System.Web.UI.WebControls.ButtonField' does not contain a definition for 'CssClass' and no extension method 'CssClass' accepting a first argument of type 'System.Web.UI.WebControls.ButtonField' could be found (are you missing a using directive or an assembly reference?) C:\Users\s06\Documents\Visual Studio 2013\WebSites\Model.aspx.cs 74 25 Pred
【问题讨论】:
-
你能告诉我们
buttonField的定义吗? -
酷!让我更新我的帖子
-
实际的错误信息也会有所帮助 - 我确定这不是“没有扩展属性和没有扩展 cssClass”
-
我已经编辑了我的帖子你是说这部分吗?
-
您使用的是什么版本的 .net?这在 4.0 和 4.5 之间移动
标签: c# extension-methods