Accessing template properties in a DataGrid
-
I have a DataGrid in which I am adding columns dynamically to the grid, I followed the example from MSDN website, and created a class that implements ITemmplate. In this class though, I want to hold some more information about the column, and later, when proccessing events on the page, I want to be able to access this information. ie.
public class DataGridTemplate : System.Web.UI.ITemplate { public ListItemType templateType; public string columnName; public string fieldName; public DataGridTemplate(ListItemType type,string colname, string fname) { templateType = type; columnName = colname; fieldName = fname; } .. ..
When handling an event on the page, I want to be able to acess the fieldName variable. So, if on the calling page I have a button_click event, andforeach(DataGridItem ditem in DataGrid.Items) { foreach(TableCell tcell in dItem.Cells) { // How would access the fieldName/etc for DataGridTemplate from here? } }
-
I have a DataGrid in which I am adding columns dynamically to the grid, I followed the example from MSDN website, and created a class that implements ITemmplate. In this class though, I want to hold some more information about the column, and later, when proccessing events on the page, I want to be able to access this information. ie.
public class DataGridTemplate : System.Web.UI.ITemplate { public ListItemType templateType; public string columnName; public string fieldName; public DataGridTemplate(ListItemType type,string colname, string fname) { templateType = type; columnName = colname; fieldName = fname; } .. ..
When handling an event on the page, I want to be able to acess the fieldName variable. So, if on the calling page I have a button_click event, andforeach(DataGridItem ditem in DataGrid.Items) { foreach(TableCell tcell in dItem.Cells) { // How would access the fieldName/etc for DataGridTemplate from here? } }
...why is it the most obvious things I try last?
public void SaveGrid() { TemplateColumn tc = (TemplateColumn)DataGrid1.Columns[0]; Debug.WriteLine(((WOGridTemplate)tc.ItemTemplate).fieldName); }