我有一个带有网格模板列的telerik radgrid绑定,通过调用后面的代码来决定删除图标的可见性ISDeleteVisible带有来自相应列的变量作为参数传递但是当我加载页面时它表示服务器标签是没有很好的错误。
<telerik:GridTemplateColumn AllowFiltering="false" UniqueName="Options">
<ItemTemplate>
<asp:ImageButton ID="imgDelete" runat="server" CommandName="cmdDelete" ToolTip="Delete"
Visible="<%# ISDeleteVisible(Eval("AgencyType") %>" CommandArgument="Container.DataItemIndex"
CausesValidation="False" ImageUrl="<%$ Resources:WebResource, deleteIcon %>"
OnClientClick="javascript:return confirm('Are you sure you want to delete?');" />
</ItemTemplate>
<ItemStyle Width="100px" />
</telerik:GridTemplateColumn>
在后面的代码中,我将方法背后的代码作为
protected bool ISDeleteVisible(string AgencyType)
{
if(AgencyType=="HouseHoldAgency")
ISDELETE = true;
else
ISDELETE = false;
return ISDELETE;
}
答案 0 :(得分:0)
您在Eval之后缺少一个结束括号(&#34; AgencyType&#34;)。
此外,只要属性值以内联方式绑定,就使用单引号而不是双引号:
Visible='<%# ISDeleteVisible(Eval("AgencyType")) %>'
无关 ,但您的代码隐藏方法存在许多问题。首先,你可以像这样写一行:
protected void IsDeletedVisible(string agencyType)
{
return AgencyType == "HouseHoldAgency";
}
如果您不想这样写,那么需要声明您的ISDELETED变量。如果它是局部变量,则需要声明它,如下所示:
bool isDeleted;
此外,在编写代码时,大写与小写很重要。在决定是否使用大写字母或小写字母表示方法,变量,属性等名称时应该小心。