Iterate through DataSource of a grid

4 posts, 0 answers
  1. Michael Love
    Michael Love avatar
    49 posts
    Member since:
    Sep 2009

    Posted 21 Apr 2010 Link to this post

    Hi there.

    How would I iterate through the DataSource of a grid? I have items that are not in a column, but are part of the datasource that I need to get at.

    Thanks, Mike
  2. robertw102
    robertw102 avatar
    265 posts
    Member since:
    Jul 2007

    Posted 21 Apr 2010 Link to this post

    You can handle the ItemDatabound event of the RadGrid and cast the DataItem object to get at the columns you need.

    I hope that helps.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Michael Love
    Michael Love avatar
    49 posts
    Member since:
    Sep 2009

    Posted 21 Apr 2010 Link to this post

    Hi Robert.

    Thanks for the reply. I need to do it when processing a button click.

    Mike
  5. robertw102
    robertw102 avatar
    265 posts
    Member since:
    Jul 2007

    Posted 21 Apr 2010 Link to this post

    In that case, you could add them to the DataKeyNames collection of your RadGrid and then access them in the button click. Like so:

    foreach (GridDataItem item in RadGrid1.Items) 
                { 
                    item.GetDataKeyValue("DataKeyName"); 
                } 

    You can iterate through the items collection and then pass the DataKeyName that you want to know the value of.

    I hope that helps.
Back to Top