Link to home
Start Free TrialLog in
Avatar of KavyaVS
KavyaVS

asked on

ListView PagePropertiesChanging event

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.
Avatar of jafrazee
jafrazee

Without knowing what your data looks like I believe there is a much easier way to do this.
Is to bind the the 2nd listview to the first listview via the datakeyname
Avatar of KavyaVS

ASKER

I didn't understand.
Can you please explain ?

Thanks
I have an example that I just posted
www.tdsm.com/testscreen/default.aspx
(ignore the css I have to fix it)
But in the example I did not need to create any codebehind
I created a list view (parent) -- I bound it to a sql query.  I set the datakeyname to my join ID (in this case the group ID)  
<asp:ListView ID="ListView1" runat="server" DataSourceID="Groups" DataKeyNames="Group_id">


When I select a group from the first list view it will show all the employees that belong to that group in the second listview.
The query for the second listview will have a ControlParameter that looks like this.
<SelectParameters>
      <asp:ControlParameter ControlID="ListView1" Name="group_id"    PropertyName="SelectedValue"
                    Type="String" />
</SelectParameters>

 
sorry had a typeo
I have an example that I just posted
www.tdsm.com/testscreen/default.aspx
(ignore the css I have to fix it)
But in the example I did not need to create any codebehind
I created a list view (parent) -- I bound it to a sql query.  I set the datakeyname to my join ID (in this case the group ID)  
<asp:ListView ID="ListView1" runat="server" DataSourceID="Groups" DataKeyNames="Group_id">


When I select a group from the first list view it will show all the employees that belong to that group in the second listview.
The query for the second listview will have a ControlParameter that looks like this.
<SelectParameters>
      <asp:ControlParameter ControlID="ListView1" Name="Group_id"    PropertyName="SelectedValue"
                    Type="String" />
</SelectParameters>
Avatar of KavyaVS

ASKER

Thanks for your reply. I am not using the sql datasource. I am creating a data table from object array in the code behind for ListView datasource.
 
This is my firstListView,secondListView  source.
 
 <asp:ListView ID="firstListView" runat="server" DataKeyNames="Path"
                                                      OnSelectedIndexChanging="firstListView_SelectedIndexChanging">
                                                        <LayoutTemplate>
                                                  <table style="border: solid 2px #336699;" cellspacing="0"
                                                  cellpadding="3" rules="all">
                                                   <tr style="background-color: #336699; color: White;">
                                                      <th>History</th>
                                                       <th>Name</th>
                                                   <th>Path</th>
                                                   <th>Type</th>
                                                   <th>ModifiedDate</th>
                                                   <th>ModifiedBy</th>
                                                      </tr>
                                                     <tbody>
                                                    <asp:PlaceHolder ID="ItemPlaceHolder" runat="server" />
                                                   </tbody>
                                                      </table>
                                                    </LayoutTemplate>
                                                     <ItemTemplate>
                                                     <tr>
                                                       <td>
                                                    <asp:LinkButton ID="lnkSelect" Text="History" CommandName="Select" runat="server" />
                                                     </td>
                                                        <td><asp:Label runat="server" ID="lblName"><%#Eval("Name") %></asp:Label></td>
                                                       <td><asp:Label runat="server" ID="lblPath"><%#Eval("Path") %></asp:Label></td>
                                                        <td><asp:Label runat="server" ID="lblType"><%#Eval("ModifiedDate")%></asp:Label></td>
                                                       <td><asp:Label runat="server" ID="lblDate"><%#Eval("Type")%></asp:Label></td>                                                  
                                                       <td><asp:Label runat="server" ID="Label1"><%#Eval("ModifiedBy")%></asp:Label></td>
                                                        </tr>
                                                       </ItemTemplate>
                                                        <AlternatingItemTemplate>
                                                        <tr style="background-color:#EFEFEF">
                                                           <td>
                                                    <asp:LinkButton ID="lnkSelect" Text="History" CommandName="Select" runat="server" />
                                                     </td>
                                                         <td><asp:Label runat="server" ID="lblName"><%#Eval("Name") %></asp:Label></td>
                                                        <td><asp:Label runat="server" ID="lblPath"><%#Eval("Path") %></asp:Label></td>
                                                         <td><asp:Label runat="server" ID="lblType"><%#Eval("ModifiedDate")%></asp:Label></td>
                                                       <td><asp:Label runat="server" ID="lblDate"><%#Eval("Type")%></asp:Label></td>                                                  
                                                       <td><asp:Label runat="server" ID="Label1"><%#Eval("ModifiedBy")%></asp:Label></td>
                                                        </tr>
                                                        </AlternatingItemTemplate>
                                                         <SelectedItemTemplate>
                                                        <tr style="background-color: #336699; color: White;">
                                                         <td>
                                                        <asp:LinkButton ID="lnkSelect" Text="History" CommandName="Select" runat="server"
                                                       ForeColor="White" />
                                                      </td>
                                                          <td><asp:Label runat="server" ID="lblName"><%#Eval("Name") %></asp:Label></td>
                                                        <td><asp:Label runat="server" ID="lblPath"><%#Eval("Path") %></asp:Label></td>
                                                         <td><asp:Label runat="server" ID="lblType"><%#Eval("ModifiedDate")%></asp:Label></td>
                                                       <td><asp:Label runat="server" ID="lblDate"><%#Eval("Type")%></asp:Label></td>                                                  
                                                       <td><asp:Label runat="server" ID="Label1"><%#Eval("ModifiedBy")%></asp:Label></td>
                                                        </tr>
                                                      </SelectedItemTemplate>

                                                        </asp:ListView>
                                                     </asp:TableCell>
                                                                                                     
                                                           
                                                         </asp:TableRow>
                                                        <asp:TableRow SkinID="GeneralRowSkin">
                                                        <asp:TableCell>
                                                        </asp:TableCell>
                                                   
                                                           <asp:TableCell >
                                                  <asp:ListView ID="secondListView" runat="server" DataKeyNames="HistoryID"
                                                     OnPagePropertiesChanging="secondListView_PagePropertiesChanging"  OnSelectedIndexChanging="secondListView_SelectedIndexChanging">
                                                   <LayoutTemplate>
                                                  <table style="border: solid 2px #336699;" cellspacing="0"
                                                  cellpadding="3" rules="all">
                                                   <tr style="background-color: #336699; color: White;">
                                                   <th>Select</th>
                                                   <th>History ID</th>
                                                    <th>Creation Date</th>
                                                    <th>Size</th>
                                                      </tr>
                                                     <tbody>
                                                    <asp:PlaceHolder ID="itemPlaceHolder" runat="server" />
                                                   </tbody>
                                                      </table>
                                                      <asp:DataPager  ID="ItemDataPager" runat="server" PageSize="5" PagedControlID="secondListView">
                                                   
                                                     <Fields>
                                                      <asp:NumericPagerField ButtonCount="3" />
                                                      </Fields>
                                                     

                                                      </asp:DataPager>
                                                   
                                                    </LayoutTemplate>
                                                    <ItemTemplate>
                                                     <tr>
                                                     <td>
                                                    <asp:LinkButton ID="lnkSelect" Text="ViewInstance" CommandName="Select" runat="server" />
                                                     </td>
                                                      <td><asp:Label runat="server" ID="lblId"><%#Eval("HistoryID") %></asp:Label></td>
                                                       <td><asp:Label runat="server" ID="lblDate"><%#Eval("CreationDate")%></asp:Label></td>                                                  
                                                      <td><asp:Label runat="server" ID="lblSize"><%#Eval("Size") %></asp:Label></td>
                                                        </tr>
                                                       </ItemTemplate>
                                                        <AlternatingItemTemplate>
                                                        <tr style="background-color:#EFEFEF">
                                                         <td>
                                                    <asp:LinkButton ID="lnkSelect" Text="ViewInstance" CommandName="Select" runat="server" />
                                                     </td>
                                                        <td><asp:Label runat="server" ID="lblId"><%#Eval("HistoryID") %></asp:Label></td>
                                                       <td><asp:Label runat="server" ID="lblDate"><%#Eval("CreationDate")%></asp:Label></td>                                                    
                                                      <td><asp:Label runat="server" ID="lblSize"><%#Eval("Size") %></asp:Label></td>
                                                       </tr>
                                                   
                                                        </AlternatingItemTemplate>
                                                        <SelectedItemTemplate>
                                                        <tr style="background-color: #336699; color: White;">
                                                         <td>
                                                        <asp:LinkButton ID="lnkSelect" Text="ViewInstance" CommandName="Select" runat="server"
                                                       ForeColor="White" />
                                                      </td>
                                                        <td><asp:Label runat="server" ID="lblId"><%#Eval("HistoryID") %></asp:Label></td>
                                                       <td><asp:Label runat="server" ID="lblDate"><%#Eval("CreationDate")%></asp:Label></td>                                                    
                                                      <td><asp:Label runat="server" ID="lblSize"><%#Eval("Size") %></asp:Label></td>
                                                        </tr>
                                                      </SelectedItemTemplate>

                                                     </asp:ListView>
                                                 </asp:TableCell>
                                               
                                                </asp:TableRow>
                                             
                                        </asp:Table>
                                </asp:TableCell>

Please see my question.Where can I  initialize the ListView LinkButtons with button OnClientClick after ListView PageProperties changing event.

Thanks
                         
ASKER CERTIFIED SOLUTION
Avatar of jafrazee
jafrazee

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

ASKER

Thanks