Home All Groups Group Topic Archive Search About
Author
4 May 2005 11:58 AM
Trond
I have an ASP.NET page that is displaying data from a dataset in a datagrid.
All columns are bound. In code behind file i use ItemDataBound event to do
some formatting of some off the columns. Insted of changing the
cell.BackColor = Color.Green; i want to add a checkbox and set it to checked
if true and unchecked if not ( in the else loop). Is this possible?

Best regards
Trond

private void dgMessages_ItemDataBound_1(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)

{

try

{

if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==

ListItemType.AlternatingItem)

{

TableCell cell = e.Item.Cells[7];

long Timediff = long.Parse(cell.Text);

if (Timediff == 1 || Timediff == 3 || Timediff == 5 || Timediff == 7 ||
Timediff == 9 || Timediff==11 || Timediff == 13 ||Timediff == 15 )

{

cell.BackColor = Color.Green;

cell.Text="OK";

}

else

{

cell.BackColor = Color.Red;

cell.Text="-";

}

Author
4 May 2005 2:06 PM
ural
Have a
<asp:TemplateColumn HeaderText="Check">
<ItemTemplate>
<asp:CheckBox ID="temp" Runat="server"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
in your aspx.
in item databound event handler say
(assume this check box is at the 1 column)
System.Web.UI.WebControls.CheckBox objChck =
(System.Web.UI.WebControls.CheckBox)e.Item.Cells[1].FindControl("temp");

Then based on your condition check or uncheck this objChck.

Hope this helps!!
Ural
Show quoteHide quote
"Trond" wrote:

> I have an ASP.NET page that is displaying data from a dataset in a datagrid.
> All columns are bound. In code behind file i use ItemDataBound event to do
> some formatting of some off the columns. Insted of changing the
> cell.BackColor = Color.Green; i want to add a checkbox and set it to checked
> if true and unchecked if not ( in the else loop). Is this possible?
>
> Best regards
> Trond
>
> private void dgMessages_ItemDataBound_1(object sender,
> System.Web.UI.WebControls.DataGridItemEventArgs e)
>
> {
>
> try
>
> {
>
> if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
>
> ListItemType.AlternatingItem)
>
> {
>
> TableCell cell = e.Item.Cells[7];
>
> long Timediff = long.Parse(cell.Text);
>
> if (Timediff == 1 || Timediff == 3 || Timediff == 5 || Timediff == 7 ||
> Timediff == 9 || Timediff==11 || Timediff == 13 ||Timediff == 15 )
>
> {
>
> cell.BackColor = Color.Green;
>
> cell.Text="OK";
>
> }
>
> else
>
> {
>
> cell.BackColor = Color.Red;
>
> cell.Text="-";
>
> }
>
>
>