Click here to Skip to main content
15,889,096 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I normally use gridview. When i want to display only 3 items in gridview, I use databound as follows and it works fine:
C#
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if(e.Row.RowType == DataControlRowType.DataRow)
        {
            if(e.Row.RowIndex >2)
            {
                e.Row.Attributes.Add("style", "display:none");
            }
        }
    }


Now i want to use similar code in listview. I tried the following code for displaying only 4 items of listview:
C#
protected void newestListView_ItemDataBound(object sender, ListViewItemEventArgs e)
    {
        if (newestListView.Items.DataItemIndex > 3)
        {
            e.Items.Attributes.Add("style", "display:none;");
        }
    }


This gives me an error:
C#
Compiler Error Message: CS1061: 'System.Collections.Generic.IList<System.Web.UI.WebControls.ListViewDataItem>' does not contain a definition for 'DataItemIndex' and no extension method 'DataItemIndex' accepting a first argument of type 'System.Collections.Generic.IList<System.Web.UI.WebControls.ListViewDataItem>' could be found (are you missing a using directive or an assembly reference?)

Kindly help me with proper code. I am using ASP.NET C#

Many thanks for your help

What I have tried:

I have tried Index , DataItme Index also in place of ItemIndex but it did not work
Posted
Updated 1-Dec-16 8:44am

1 solution

Did you tried dataItem.DisplayIndex or dataItem.DataItemIndex? Where dataItem is:
ListViewDataItem dataItem = (ListViewDataItem)e.Item
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900