Hey everyone,
I need to set custom attributes on a control as it is bound to a datalist. I see that the event arguments has a collection of controls but I do not see any reference name associated with them. How can this be done?
When I try this:
(e.Item.FindControl("autoChartChkBox") as CheckBox).Attributes.Add("CompanyToken", "CompanyToken");
The control is always 'null'. The control I am trying to locate is added in my data template. This is my ItemTemplate assignment and below is the actual temple. Notice the protected CheckBox autoChartChkBox; This is the control I am trying to manipulate via the OnDataItemBound event.
alertList.ItemTemplate = new AlertItemTemplate(groupTracker);
private class AlertItemTemplate : ItemTemplateBase
{
private readonly GroupHeaderTracker groupTracker;
protected CheckBox autoChartChkBox;
public override void DataBind()
{
Label autoChartLbl;
Alert item = (Alert)((DataListItem)this.NamingContainer).DataItem;
CultureInfo info = Thread.CurrentThread.CurrentCulture;
titleText.Text = String.Format("{0} - {1}", item.DateCreated.ToString(info.DateTimeFormat.ShortDatePattern), item.ID);
this.bodyText.Text = item.Text;
Color color = GetAlertColor(item.AlertType.Color);
colorDisplay.BackColor = color;
this.groupTracker.SetCurrentAlertTypeId(item.AlertType.ID);
if(this.groupTracker.IsNewGroup())
{
this.alertTypeNameLabel.Text = item.AlertType.Name;
this.alertTypeNameRow.Visible = true;
this.alertTypeNameRow.Cells[0].Style.Add("border-top", string.Format("solid thin {0}",GetColorHexValue(color)));
this.alertTypeNameRow.Cells[0].Style.Add("border-bottom", string.Format("solid thin {0}",GetColorHexValue(color)));
//Auto Chart
TableCell autoChartCell;
autoChartCell = new TableCell();
autoChartCell.Width = 50;
autoChartCell.BorderStyle = BorderStyle.Solid;
autoChartCell.VerticalAlign = VerticalAlign.Top;
autoChartCell.Controls.Add(autoChartChkBox = new CheckBox());
autoChartCell.Controls.Add(autoChartLbl = new Label());
Rows[1].Cells.Add(autoChartCell);
autoChartLbl.Text = "AutoChart";
autoChartChkBox.Checked = item.IncludeInChartNotes;
alertTypeNameCell.ColumnSpan = Rows[1].Cells.Count;
}
Can someone save me? :)
Thanks!
-Nick