Array bound to Datagrid - getting values out of the datagrid

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.
 
G

g.o.atkins

I should have added that the ArrayList is just an array of strings.
Also find the html below

<asp:DataGrid id="_dgModerators" runat="server"
AutoGenerateColumns="False" AllowSorting="False" >
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<%# Container.DataItem %>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:CheckBox id="_chkRemove" runat="server"
Checked="False"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top