DataGrid finding a control
Posted
by nat
on Stack Overflow
See other posts from Stack Overflow
or by nat
Published on 2009-12-10T12:02:58Z
Indexed on
2010/04/19
2:03 UTC
Read the original article
Hit count: 470
HI
I have a DataGrid (yes would be nicer if it was a gridview but nothing i can do about that)
in the itemDataBound event i am adding a hidden field into the first cell of each row I am setting its ID based on something, and then saving its clientID in a List for later attempts to get the value from it
but try as i might i cant find anything with findcontrol
have tried
here is the itemdatabound bit
foreach(page in datasource){
HiddenField hidOrder = new HiddenField();
hidOrder.ID = "order_" + page.Id.ToString();
hidOrder.Value = page.Ordering.ToString();
e.Item.Cells[0].Controls.Add(hidOrder);
idList.Add(hidOrder.ClientID);
}
then this is a button click event..
int numRows = FrontEndDataGrid.Items.Count;
for (int i = 0; i < numRows; i++){
foreach(string hidID in idList){
HiddenField hf = FrontEndDataGrid.Items[i].FindControl(hidID) as HiddenField;
//ssadly this never finds anything
//have also tried looping around the cells for each 'row' - no luck there either
}
}
any ideas?
thanks
nat
© Stack Overflow or respective owner