views:

17

answers:

1

Hello guys,

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

+2  A: 

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>
matt-dot-net
Thanks very much, this solution worked fine; and yes, Im using templateField because insertion...
Pmdusso
Just one more question, if I need to get the checked change, how do I do it? Just declare de OnCheckedChange in the aspx and them create the method in the .cs?
Pmdusso
Yep! that's all you have to do
matt-dot-net