troubleshooting Question

ListView PageProperties Changing Event

Avatar of KavyaVS
KavyaVS asked on
ASP.NET
2 Comments1 Solution434 ViewsLast Modified:
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
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 2 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros