E
Ethan Strauss
Hi,
I want to use a Gridview control to display a list of item names each
associated with two checkboxes. The goal is for the user to be able to
designate two Boolean characteristics of each item. The list of names will
NOT be coming from a database. This seems simple, but I can't figure out how
to do it.
I have tried creating three columns on the .ascx page. Two checkbox columns
and one bound column for the items names. I can't get any of these columns to
populate from code. When I set the datasource to a List<string> of the
names, I get nothing I AutoGenerateColumns == false and a new column added
with the names if AutoGenerateColumns == true. I have creating all three
columns from code and I can get the columns to exist, but I never see any
checkboxes.
Does anyone know of a good example which does not use binding to a SQL type
datasource?
Thanks!
Ethan
Here is the code I have used to add all the columns programmatically. I see
four columns, but only the autogenerated one has any text or visible controls
in it.
DataControlField UseSequence = new CheckBoxField();
UseSequence.Visible = true;
DataControlField ReverseComplement = new CheckBoxField();
DataControlField SequenceName = new BoundField();
GridView1.Columns.Add(UseSequence);
GridView1.Columns.Add(ReverseComplement);
GridView1.Columns.Add(SequenceName);
int index = 0;
foreach (string name in sequenceNames)
{
DataControlFieldCell cell = new
DataControlFieldCell(SequenceName);
cell.Text = name;
SequenceName.InitializeCell(cell,
DataControlCellType.DataCell, DataControlRowState.Normal, index);
DataControlFieldCell useCell = new
DataControlFieldCell(UseSequence);
useCell.Controls.Add(new CheckBox());
UseSequence.InitializeCell(useCell,
DataControlCellType.DataCell, DataControlRowState.Normal, index);
DataControlFieldCell rcCell = new
DataControlFieldCell(ReverseComplement);
ReverseComplement.InitializeCell(rcCell,
DataControlCellType.DataCell, DataControlRowState.Normal, index);
index++;
}
GridView1.AutoGenerateColumns = true;
GridView1.DataSource = sequenceNames;
GridView1.DataBind();
GridView1.Visible = true;
GridView1.BackColor = System.Drawing.Color.Pink;
I want to use a Gridview control to display a list of item names each
associated with two checkboxes. The goal is for the user to be able to
designate two Boolean characteristics of each item. The list of names will
NOT be coming from a database. This seems simple, but I can't figure out how
to do it.
I have tried creating three columns on the .ascx page. Two checkbox columns
and one bound column for the items names. I can't get any of these columns to
populate from code. When I set the datasource to a List<string> of the
names, I get nothing I AutoGenerateColumns == false and a new column added
with the names if AutoGenerateColumns == true. I have creating all three
columns from code and I can get the columns to exist, but I never see any
checkboxes.
Does anyone know of a good example which does not use binding to a SQL type
datasource?
Thanks!
Ethan
Here is the code I have used to add all the columns programmatically. I see
four columns, but only the autogenerated one has any text or visible controls
in it.
DataControlField UseSequence = new CheckBoxField();
UseSequence.Visible = true;
DataControlField ReverseComplement = new CheckBoxField();
DataControlField SequenceName = new BoundField();
GridView1.Columns.Add(UseSequence);
GridView1.Columns.Add(ReverseComplement);
GridView1.Columns.Add(SequenceName);
int index = 0;
foreach (string name in sequenceNames)
{
DataControlFieldCell cell = new
DataControlFieldCell(SequenceName);
cell.Text = name;
SequenceName.InitializeCell(cell,
DataControlCellType.DataCell, DataControlRowState.Normal, index);
DataControlFieldCell useCell = new
DataControlFieldCell(UseSequence);
useCell.Controls.Add(new CheckBox());
UseSequence.InitializeCell(useCell,
DataControlCellType.DataCell, DataControlRowState.Normal, index);
DataControlFieldCell rcCell = new
DataControlFieldCell(ReverseComplement);
ReverseComplement.InitializeCell(rcCell,
DataControlCellType.DataCell, DataControlRowState.Normal, index);
index++;
}
GridView1.AutoGenerateColumns = true;
GridView1.DataSource = sequenceNames;
GridView1.DataBind();
GridView1.Visible = true;
GridView1.BackColor = System.Drawing.Color.Pink;