Link to home
Start Free TrialLog in
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
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of KavyaVS
KavyaVS

ASKER

Thanks