how to check/Uncheck a checkbox dynamically in a datagrid in asp.net

  • Thread starter Thread starter Neal
  • Start date Start date
N

Neal

HI all,

I have an issue with check box in datagrid.
I would like it to check and uncheck based on a database value of NULL
or a Date Value.

If there is a date value for that column then check the check box in
datagrid

If the value is null then keep it unchanged as (Unchecked)

this is in asp.net

Your help is appreciated

Thank you

Neal
 
hi,

Datagrid code with check box and date field

<asp:DataGrid id="grdAuthors" runat="server" Width="626px">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:CheckBox ID="chkbox" Runat="server"></asp:CheckBox>
</ItemTemplate>
</asp:BoundColumn>
</Columns>
</asp:DataGrid>

and with dataItemBound event of grid u can write code as below


string _lblDate = e.Item.Cells[1].Text.ToString(); //date column
CheckBox _chkBox = (CheckBox)e.Item.FindControl("chkbox");
if(_chkBox != null)
{
if(_lblDate == "True")//Here u can check if some date text is
//bound with the label
{
_chkBox.Checked = true;
}
}
 
Back
Top