Home All Groups Group Topic Archive Search About
Author
1 Apr 2005 9:48 AM
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

Author
1 Apr 2005 1:32 PM
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
elton_w***@hotmail.com

>-----Original Message-----
>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");
Show quoteHide quote
>
>//pseudocode
>if ..... <<check the paid status>>
>then .......
>
>i keep getting "Specified cast is invalid" error.
>
>please help,
>
>Hendri Irawan
>
>
>
>
>.
>