how to use check box in data grid

H

Hendri Irawan

hi all, please help me

I want to use check box in data grid for boolean value, let said about an
invoice record paid status. I've used TemplateColumn for this purpose.

<asp:datagrid id="dgrInvoices" runat=server>
<asp:TemplateColumn><asp:checkbox id="chkPaid"
runat="server"></asp:checkbox></asp:TemplateColumn>
<asp:BoundColumn>..........<<several bound column>>
</asp:datagrid>

has i done it right ?

now, if an invoice record paid status is true i want the checkbox to be
checked. i've try this

in the datagrid event ItemCreated (is this the right event or the
ItemDataBound ?), if put
//real C# code
//make a reference
CheckBox chkToUpdate = (CheckBox)e.Item.Cells[0].FindControl("chkPaid");

//pseudocode
if ..... <<check the paid status>>
then .......

i keep getting "Specified cast is invalid" error.

please help,

Hendri Irawan
 
E

Elton Wang

Hi Hendri,

The checkbox should be inside ItemTemplate tags. It's like

<asp:TemplateColumn HeaderText="Header">
<ItemTemplate>
<asp:checkbox id="chkPaid" runat="server"></asp:checkbox>
</ItemTemplate>
</TemplateColumn>

HTH

Elton Wang
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,525
Members
44,997
Latest member
mileyka

Latest Threads

Top