Array bound to Datagrid - getting values out of the datagrid

Discussion in 'ASP .Net' started by g.o.atkins@gmail.com, Sep 14, 2006.

  1. Guest

    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.
     
    , Sep 14, 2006
    #1
    1. Advertising

  2. Guest

    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>
     
    , Sep 14, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sunil panda

    Lower bound & Upper bound

    sunil panda, Dec 25, 2003, in forum: Java
    Replies:
    9
    Views:
    7,266
    thushara wijeratna
    Oct 7, 2008
  2. Rhiner Dan
    Replies:
    1
    Views:
    750
    Mike Wahler
    Mar 27, 2005
  3. Mario Krsnic
    Replies:
    0
    Views:
    386
    Mario Krsnic
    Jun 23, 2006
  4. Phillip Vong
    Replies:
    0
    Views:
    418
    Phillip Vong
    Jul 27, 2006
  5. pauld
    Replies:
    0
    Views:
    325
    pauld
    May 9, 2008
Loading...

Share This Page