Anyone Know The Best Way...?

T

Tom Carter

I have a problem and I hope someone smarter than I can help me to
solve it.

What I want to do:
Dynamically create a template column with a control in it
Display nested related data in the control

Constraints:
Cannot use relations because some of the related values may be null

What I have researched already:
using Nested Datagrids
using Nested XML
using Nested Literal Controls

My View:
I would like to display a list of names in the Item Template, I have
seen some posts that suggest Item_DataBound is the appropriate place
to create the data and control for each row.

Following this I would like to display a list of the same names with
checkboxes next to them for the Edit Item Template

NOTE:
I am considering using a dataview since I already have access to the
dataset tables and a sort could use a value from one of the cells on
each row (returning a dataview that would be bound to the control)

Questions:
Is binding a dataview to a control in the Item_DataBound event a good
idea?

How do I access the individual cell values for a row (ie - how can I
know which row i am on)?

Is there a more efficent way to handle this?

Does the Item_DataBound fire after each row is bound to data?

Would there be any problem creating a function that is called in the
Item_DataBound with a particular cell value (this value would be the
value by which one ought to sort the secondary table)?

What control should I use since I only want to display a list of
strings in the datagrid initially?

What control should I use when I setup the edit control considering
that the list should allow me to add/delete strings of the list?


Thanks in advance for any assistance
(my head is really starting to hurt...)

Sincerely,
Lost Coder
(Tommie)

** CODE FOLLOWS **

//this adds a column based on some external criteria
private void test()
{
TemplateColumn tc = new TemplateColumn ();
tc.HeaderTemplate = new DataGridTemplate (ListItemType.Header,
"MyNewColumn");
tc.ItemTemplate = new DataGridTemplate (ListItemType.Item,
"MyNewColumn");
tc.EditItemTemplate = new DataGridTemplate (ListItemType.EditItem ,
"MyNewColumn");
tc.SortExpression = "SortHandler.Test";

//thedg is a datagrid loaded in page_load

thedg.Columns.AddAt (1,tc);
}
public class DataGridTemplate:ITemplate
{
ListItemType templateType;
string columnName;

public DataGridTemplate(ListItemType type, string colname)
{
templateType = type;
columnName = colname;
}

#region ITemplate Members

public void InstantiateIn(Control container)
{
Literal lc = new Literal ();
switch (templateType)
{
case ListItemType.Header:
lc.ID = "lstNewControl";
lc.Text = "<B>" + columnName + "</B>";
container.Controls.Add (lc);
break;
case ListItemType.Item :
TextBox tb = new TextBox ();
tb.Text = "";

container.Controls.Add (tb);
break;
case ListItemType.Footer :
lc.Text ="<I>" + columnName + "</I>";
break;
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,124
Latest member
JuniorPell
Top