Hi,
It sounds like you want to do something similar to what I have just
written. In my example dgDupManager is a datagrid. I wanted to iterate
the grid and find the controls buried in template columns (Item,
Alternating, Selected, etc) within each row of the grid. I used an
array list to make the controls easily accessible to me. The array
list in my example is called activeControls. Since I wanted to change
the values for these select controls I thought it would be easiser to
do with an array list because the grid had many controls that I do not
care to change.
for(int i=0;i<dgDupManager.Items.Count ;i++)
if (dgDupManager.Items.HasControls())
for(int n=0;n<dgDupManager.Items.Cells.Count ;n++)
if (dgDupManager.Items.Cells[n].HasControls())
foreach (Control c in dgDupManager.Items.Cells[n].Controls)
if (c.GetType().ToString().IndexOf("DropDownList")>0 ||
c.GetType().ToString().IndexOf("Button")>0)
//add a specific type of control into my array
list
activeControls.Add(c); //defined in my Page as ArrayList
The way that I parse my Array List and make changes to the control
values can be seen in this routine (which is executed when a button is
clicked). The goal in my case was to have the button change values for
selected controls between itself and the next button. I used another
trick of the datagrid to enable me to only place the buttons into an
artificially generated sub-header for the datagrid. The
assembleActiveControls method contains only the code above. The
activeControls[x] (see below) just allows me to go through the
controls that I care about without searching the datagrid. This kind
of functionality is good when you will build a datagrid that has
dynamically created controls or whose control id's are unknown to you.
//reference clicked button
System.Web.UI.WebControls.Button _button =
(System.Web.UI.WebControls.Button) sender;
//parse dropdownlist and button controls into an arraylist
assembleActiveControls();
//find location of the clicked button and reference next controls in
arraylist
int x = activeControls.LastIndexOf(_button) + 1;
//toggle the records in the clicked subheader
while(x < activeControls.Count &&
!
activeControls[x].GetType().ToString().Equals("System.Web.UI.WebControls.Button") )
{
DropDownList _temp = (DropDownList)activeControls[x];
//toggle the active controls based on the button clicked
if (_button.Text == "Process")
_temp.SelectedIndex = 1;
if (_button.Text == "Filter")
_temp.SelectedIndex = 0;
x++;
}
Hopefully, this will help someone since I just spent a weekend
thinking about the best way to handle this question. The above is not
completely finished code but hopefully its enough so that anyone
trying to do this in the future can get a good sense of how to
address.