views:

41

answers:

1

Hello,

I have a Datalist and I am trying to insert a checkbox for each record that gets bound to the datalist. The first record has the checkbox but the subsequent records do not. I suspect that what I am doing is just replacing the first checkbox eachtime a record is bound. Can someone give me some insight? I need the checkbox to be repeated for each record.

 alertList.ItemTemplate = new AlertItemTemplate(groupTracker);

        if (!Page.IsPostBack) {
            alertList.DataBind();
        }

Here is my overridden bind method:

 public override void DataBind() 
        {
                 //Auto Chart
                TableCell autoChartCell;
                autoChartCell = new TableCell();
                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;

            }
        }
+1  A: 

Add the required controls in your view markup, then show/hide programmatically as necessary.

Putting this kind of code in code-behinds is generally discouraged as it breaks the controller/view model.

Jon Seigel
Agreed.. This is an old project that I'm extending. Isn't that always the way it is? :)
Nick