Avatar of KavyaVS
KavyaVS
 asked on

ListView PageProperties Changing Event

This is my code

protected void secondListView_PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)
        {
            DataPager pager =
(DataPager)((ListView)sender).FindControl("ItemDataPager");
            pager.SetPageProperties(e.StartRowIndex, e.MaximumRows, false);
             DataTable dtHistory =GetReportHistory(strChildNode);
            DataView dataView = new DataView(dtHistory);
            dataView.Sort = "HistoryID DESC";
             secondListView.DataSource = dataView;
            secondListView.DataBind();
            foreach (ListViewDataItem item in secondListView.Items)
            {

                DataKey currentDataKey
=secondListView.DataKeys[item.DataItemIndex];
                LinkButton btnlink = (LinkButton)item.FindControl("lnkSelect");
                btnlink.OnClientClick =
"window.open('Report_Form.aspx?Reportpath=" + strCNode + "&SnapshotID=" +
               currentDataKey.Value.ToString()   +
"',null,'height=1000, width=1000,status= no,resizable= yes, scrollbars=yes, toolbar=no,location=no,menubar=no ');return false";
            }


        }
Here I am getting the index out of range exception.
 DataKey currentDataKey =secondListView.DataKeys[item.DataItemIndex];

Can I use something like this
for (int j = 0; j>=e.startRowIndex; j++)
{
  ListViewItem item = (ListViewItem)this.secondListView.Items;
DataKey currentDataKey =secondListView.DataKeys[item[j].DataItemIndex];
   LinkButton btnlink = (LinkButton)item.FindControl("lnkSelect");
                btnlink.OnClientClick =
"window.open('Report_Form.aspx?Reportpath=" + strCNode + "&SnapshotID=" +
               currentDataKey.Value.ToString()   +
"',null,'height=1000, width=1000,status= no,resizable= yes, scrollbars=yes, toolbar=no,location=no,menubar=no ');return false";

}
I am getting this error.Cannot apply indexing with [] to an expression of type 'System.Web.UI.WebControls.ListViewItem'.
Please let me know how to fix the index out of range exception after  Data Paging. How to add button onclient click event to LinkButton after paging.
Thanks
ASP.NET

Avatar of undefined
Last Comment
KavyaVS

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Bob Learned

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
KavyaVS

ASKER
Thanks
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23