troubleshooting Question

ListView PagePropertiesChanging event

Avatar of KavyaVS
KavyaVS asked on
ASP.NET
7 Comments1 Solution2719 ViewsLast Modified:
I have 2 listview's on .aspx page.In the First ListView SelectedIndexChanging event second Listview databinding happens and displayed
protected void firstListView_SelectedIndexChanging(object sender, ListViewSelectEventArgs e)
        {
           
            DataTable dtHis =GetReportHistory(strPath);
            DataView dataView = new DataView(dtHis);
            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";


         }

It is working fine and popup page is displaying with single click.

I have datapager associated with secondListView

<asp:DataPager  ID="ItemDataPager" runat="server" PageSize="5" PagedControlID="secondListView">
                                                   
                                                     <Fields>
                                                      <asp:NumericPagerField ButtonCount="3" />
                                                      </Fields>
                                                     

                                                      </asp:DataPager>

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";
            }


        }

DataKey currentDataKey =secondListView.DataKeys[item.DataItemIndex];at this line I am getting the Index OutOfRange exception.

Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

How to fix this error.How to initialize the ListView LinkButtons with button OnClientClick after ListView PageProperties changing event.

Thanks.

ivan_vagunin can you help me.
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 7 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 7 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