G
g.o.atkins
Hi,
I've bound an ArrayList to a datagrid and succesfully managed to
display the data via an ItemTemplate column and using <%#
Container.DataItem %>.
The problem I have however is trying to read the value back out of the
datagrid. Basically I have checkboxes next to each item in the datagrid
- when the user clicks on a button im looping through each item in the
datagrid and then trying to read the value out. This works for when a
datset is bound to a datagrid, but not for an arrayList.
My code is below. Its like the data isnt there!?! Yet the data is
redisplayed on the page being refreshed (i.e. viewstate is working).
I've even put the data within a label control within the datagrid,
hoping it would allow me get at the value, but that doesnt work either.
//loop through each datagrid item, removing moderator if necessary
foreach(DataGridItem itm in _dgModerators.Items)
{
//get current moderators list from view state
ArrayList moderators = (ArrayList)ViewState["Moderators"];
bool remove = ((CheckBox)itm.FindControl("_chkRemove")).Checked;
if(remove)
{
//remove user from moderator list
moderators.Remove(itm.Cells[0].Text);
}
//resave list to view state
ViewState["Moderators"] = moderators;
}
Thanks,
George.
I've bound an ArrayList to a datagrid and succesfully managed to
display the data via an ItemTemplate column and using <%#
Container.DataItem %>.
The problem I have however is trying to read the value back out of the
datagrid. Basically I have checkboxes next to each item in the datagrid
- when the user clicks on a button im looping through each item in the
datagrid and then trying to read the value out. This works for when a
datset is bound to a datagrid, but not for an arrayList.
My code is below. Its like the data isnt there!?! Yet the data is
redisplayed on the page being refreshed (i.e. viewstate is working).
I've even put the data within a label control within the datagrid,
hoping it would allow me get at the value, but that doesnt work either.
//loop through each datagrid item, removing moderator if necessary
foreach(DataGridItem itm in _dgModerators.Items)
{
//get current moderators list from view state
ArrayList moderators = (ArrayList)ViewState["Moderators"];
bool remove = ((CheckBox)itm.FindControl("_chkRemove")).Checked;
if(remove)
{
//remove user from moderator list
moderators.Remove(itm.Cells[0].Text);
}
//resave list to view state
ViewState["Moderators"] = moderators;
}
Thanks,
George.