Detecting BOF & EOF in the itemdatabound event

4 posts, 0 answers
  1. Andy Green
    Andy Green avatar
    342 posts
    Member since:
    Aug 2008

    Posted 03 Dec 2015 Link to this post

    Hi

    Is it possible to detect the first and last records while in the itemdatabound event - I need to handle the display for these t rows.

    Andy

  2. Viktor Tachev
    Admin
    Viktor Tachev avatar
    1488 posts

    Posted 08 Dec 2015 Link to this post

    Hi Andy,

    Checking if the current record is the last would require custom implementation that would depend on how you are binding the grid. For example, if you are using a DataTable to pass data to the RadGrid you can check if the index of the current item is equal to the number of items in the DataTable collection.

    With that said, if you would like to change the styles for the first and last items in the grid you can use CSS. The following rules set the background color for the first and last items in the grid.


    .rgMasterTable>tbody tr:first-child {
        background-color: red;
    }
     
    .rgMasterTable>tbody tr:last-child {
        background-color: red;
    }


    Regards,
    Viktor Tachev
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Andy Green
    Andy Green avatar
    342 posts
    Member since:
    Aug 2008

    Posted 08 Dec 2015 in reply to Viktor Tachev Link to this post

    Thanks Viktor

    I have solved this the following way:

    In the ItemDataBound for the first row:

    If e.Item.ItemIndex = 0 Then
        'Do stuff
    End If

    For the last row:

    If e.Item.DataSetIndex = e.Item.OwnerTableView.DataSourceCount - 1 Then
       'Do Stuff
    End If

     Might help others in my position.

    Andy

  5. Viktor Tachev
    Admin
    Viktor Tachev avatar
    1488 posts

    Posted 08 Dec 2015 Link to this post

    Hello Andy,

    Thank you for sharing your solution with the community.

    Regards,
    Viktor Tachev
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top