我在'gridview'中的这个专栏中得到了这个错误。 : -
<asp:TemplateField>
<ItemTemplate>
<a href='<%# Eval("url") %>' target="_blank" style="color:#330000; font-size:18px; font-weight:bold"><%# Eval("title") %></a>
<br />
<p runat="server" id="description"><%# Eval("des") %></p>
<asp:ImageButton ID="click_like" runat="server" ImageUrl= "~/pics/like.png" Height="20px" CommandName="like" CommandArgument='<%# Eval("id") %>' BorderStyle="Outset" BorderColor="#99CCFF" Enabled='<%# Eval("like_enabled") %>' />
<asp:Label ID="lbl_like" runat="server" Text='<%# Eval("like") %>'></asp:Label>
<asp:ImageButton ID="click_dislike" runat="server" ImageUrl="~/pics/dislike.png" Height="20px" CommandName="dislike" CommandArgument='<%# Eval("id") %>' BorderStyle="Outset" BorderColor="#99CCFF" Enabled='<%# Eval("dislike_enabled") %>'/>
<asp:Label ID="lbl_dislike" runat="server" Text='<%# Eval("dislike") %>'></asp:Label>
<p runat="server" id="labels"><%# Eval("labels") %></p>
</ItemTemplate>
</asp:TemplateField>
我收到了这个错误: -
<asp:ImageButton ID="click_like" runat="server" ImageUrl= "~/pics/like.png" Height="20px" CommandName="like" CommandArgument='<%# Eval("id") %>' BorderStyle="Outset" BorderColor="#99CCFF" Enabled='<%# Eval("like_enabled") %>' />
我得到了这个,因为我绑定了Enabled
DataTable
属性的值like_enabled
列,其中123.005
123.0
列是&#34; true&#34;或&#34; false&#34;
答案 0 :(得分:0)
您无法像这样绑定Enabled
,您必须使用RowDataBound
事件:
<asp:GridView id="myGrid" OnRowDataBound="myGrid_RowDatabound">
代码背后:
public void myGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
var enabled = (bool)DataBinder.Eval(e.Row.DataItem, "like_enabled");
var click_like = e.Row.FindControl("click_like") as ImageButton;
click_like.Enabled = enabled;
}
}