PC Review


Reply
Thread Tools Rate Thread

Array bound to Datagrid - getting values out of the datagrid

 
 
g.o.atkins@gmail.com
Guest
Posts: n/a
 
      14th Sep 2006
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.

 
Reply With Quote
 
 
 
 
g.o.atkins@gmail.com
Guest
Posts: n/a
 
      14th Sep 2006
I should have added that the ArrayList is just an array of strings.
Also find the html below

<aspataGrid 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>
</aspataGrid>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sort Datagrid bound to custom class array Ben Microsoft C# .NET 5 10th Jul 2008 11:18 PM
getting fileupload values into a form that's bound to a datagrid pauld Microsoft ASP .NET 0 9th May 2008 12:52 AM
Problem Using a DataGrid Bound to Array TommyVee Microsoft Dot NET Framework Forms 0 31st Jan 2008 03:04 PM
DataGrid Bound column with NULL values Fresh Air Rider Microsoft Dot NET 1 12th Mar 2004 08:33 PM
dynamically change datagrid bound values Saravanan Rathinavelu Microsoft ASP .NET 2 21st Aug 2003 04:09 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:30 PM.