Hi,
I have RadGrid which uses a user control (Companies.ascx) as edit form. User control contains chechboxlist and its items are populated dynamically from DB. Now I have a problem with selecting the correct checkboxlist items when grid row is in edit mode. The following code selects the items in user controls DataBinding event but after that in some phase those selection are "reset".
I have tried many different approaches and the following is just one of my tests. Can you help me with this one.
Regards,
Pete
I have RadGrid which uses a user control (Companies.ascx) as edit form. User control contains chechboxlist and its items are populated dynamically from DB. Now I have a problem with selecting the correct checkboxlist items when grid row is in edit mode. The following code selects the items in user controls DataBinding event but after that in some phase those selection are "reset".
I have tried many different approaches and the following is just one of my tests. Can you help me with this one.
private object _dataItem; |
public object DataItem |
{ |
get |
{ |
return this._dataItem; |
} |
set |
{ |
this._dataItem = value; |
} |
} |
protected override void OnInit(EventArgs e) |
{ |
base.OnInit(e); |
this.DataBinding += new EventHandler(Companies_DataBinding); |
} |
protected void Companies_DataBinding(object sender, System.EventArgs e) |
{ |
txtName.Text = DataBinder.Eval(DataItem, "CompanyName").ToString(); |
using (DBService dms = new DBService()) |
{ |
cblProducts.DataSource = dms.GetProducts(); |
cblProducts.DataBind(); |
} |
// get company's products -> string where products are separated with comma |
object objProducts = DataBinder.Eval(DataItem, "Products"); |
if (objProducts != DBNull.Value) |
{ |
foreach (string prod in objProducts.ToString().Split(',')) |
{ |
ListItem li = cblProducts.Items.FindByText(prod); |
if (li != null) |
li.Selected = true; |
} |
} |
} |
Regards,
Pete