.comment-link {margin-left:.6em;}
Books & Articles I wrote.

Friday, March 31, 2006

 

Setting DataView checkbox for custom entity

It's a pain formatting code for blogs. Save the hassles and go here.

Now, ever wanted to set a checkbox in asp.net 2.0 after you have databound to it with a custom object? This code may be useful and save you some time :

protected void ucDetailsView1_DataBound(object sender, EventArgs e)
{
DetailsView dv = sender as DetailsView;

if (dv == null)
return;

IAccount account = dv.DataItem as IAccount;
if (account != null)
{
CheckBox cb = dv.FindControl("ucMyCheckbox") as CheckBox;
if (cb != null)
cb.Checked = account.IsEnabled;
}
}

 read 0 comments | 

This page is powered by Blogger. Isn't yours?

Weblog Commenting and Trackback by HaloScan.com