Checkbox itemtemplate templatefield text after databound
I have the following checkboxes in my gridview:
<asp:TemplateField HeaderText="Active">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "Active")%>
<asp:CheckBox ID="Active" runat="server"/>
</ItemTemplate>
</asp:TemplateField>
And it working very fine. I'm populating it with a bool value. The problem is that its showing the string text in the gridview, like:
True [x] False [ ] True [开发者_运维百科x]
and so long... I would like to show just the checkboxes. I tried this in the rowDataBound event:
if (result.Active)
{
((CheckBox)e.Row.FindControl("Active")).Checked = true;
((CheckBox)e.Row.FindControl("Active")).Text = string.Empty;
}
But its not working. There is a way?
Thanks,
Pedro Dusso
Instead of TemplateField, why don't you just use the CheckBoxField?
<asp:CheckBoxField DataField="Active" HeaderText="Active" />
If you have to use TemplateField because of Insert/Edit then you should be able to do
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox id="CheckBoxActive" runat="server" Checked='<%#Eval("Active") %>' />
</ItemTemplate>
</asp:TemplateField>
精彩评论