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_SelectedInde xChanging( 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[it em.DataIte mIndex];
LinkButton btnlink = (LinkButton)item.FindContr ol("lnkSel ect");
btnlink.OnClientClick = "window.open('Report_Form. aspx?Repor tpath=" + strCNode + "&SnapshotID=" +
currentDataKey.Value.ToStr ing() + "',null,'height=1000, width=1000,status= no,resizable= yes, scrollbars=yes, toolbar=no,location=no,men ubar=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="secondList View">
<Fields>
<asp:NumericPagerField ButtonCount="3" />
</Fields>
</asp:DataPager>
protected void secondListView_PagePropert iesChangin g(object sender, PagePropertiesChangingEven tArgs e)
{
DataPager pager = (DataPager)((ListView)send er).FindCo ntrol("Ite mDataPager ");
pager.SetPageProperties(e. StartRowIn dex, e.MaximumRows, false);
DataTable dtHistory =GetReportHistory(strChild Node);
DataView dataView = new DataView(dtHistory);
dataView.Sort = "HistoryID DESC";
secondListView.DataSource = dataView;
secondListView.DataBind();
foreach (ListViewDataItem item in secondListView.Items)
{
DataKey currentDataKey =secondListView.DataKeys[i tem.DataIt emIndex];
LinkButton btnlink = (LinkButton)item.FindContr ol("lnkSel ect");
btnlink.OnClientClick = "window.open('Report_Form. aspx?Repor tpath=" + strCNode + "&SnapshotID=" +
currentDataKey.Value.ToStr ing() + "',null,'height=1000, width=1000,status= no,resizable= yes, scrollbars=yes, toolbar=no,location=no,men ubar=no ');return false";
}
}
DataKey currentDataKey =secondListView.DataKeys[i tem.DataIt emIndex];a t 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.
protected void firstListView_SelectedInde
{
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[it
LinkButton btnlink = (LinkButton)item.FindContr
btnlink.OnClientClick = "window.open('Report_Form.
currentDataKey.Value.ToStr
}
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="secondList
<Fields>
<asp:NumericPagerField ButtonCount="3" />
</Fields>
</asp:DataPager>
protected void secondListView_PagePropert
{
DataPager pager = (DataPager)((ListView)send
pager.SetPageProperties(e.
DataTable dtHistory =GetReportHistory(strChild
DataView dataView = new DataView(dtHistory);
dataView.Sort = "HistoryID DESC";
secondListView.DataSource = dataView;
secondListView.DataBind();
foreach (ListViewDataItem item in secondListView.Items)
{
DataKey currentDataKey =secondListView.DataKeys[i
LinkButton btnlink = (LinkButton)item.FindContr
btnlink.OnClientClick = "window.open('Report_Form.
currentDataKey.Value.ToStr
}
}
DataKey currentDataKey =secondListView.DataKeys[i
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.
ASKER
I didn't understand.
Can you please explain ?
Thanks
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="SelectedValu e"
Type="String" />
</SelectParameters>
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="SelectedValu
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="SelectedValu e"
Type="String" />
</SelectParameters>
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="SelectedValu
Type="String" />
</SelectParameters>
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,secondListVi ew source.
<asp:ListView ID="firstListView" runat="server" DataKeyNames="Path"
OnSelectedIndexChanging="f irstListVi ew_Selecte dIndexChan ging">
<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("Modi fiedDate") %></asp:La bel></td>
<td><asp:Label runat="server" ID="lblDate"><%#Eval("Type ")%></asp: Label></td >
<td><asp:Label runat="server" ID="Label1"><%#Eval("Modif iedBy")%>< /asp:Label ></td>
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr style="background-color:#E FEFEF">
<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("Modi fiedDate") %></asp:La bel></td>
<td><asp:Label runat="server" ID="lblDate"><%#Eval("Type ")%></asp: Label></td >
<td><asp:Label runat="server" ID="Label1"><%#Eval("Modif iedBy")%>< /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("Modi fiedDate") %></asp:La bel></td>
<td><asp:Label runat="server" ID="lblDate"><%#Eval("Type ")%></asp: Label></td >
<td><asp:Label runat="server" ID="Label1"><%#Eval("Modif iedBy")%>< /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=" secondList View_PageP ropertiesC hanging" OnSelectedIndexChanging="s econdListV iew_Select edIndexCha nging">
<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="secondList View">
<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("Histor yID") %></asp:Label></td>
<td><asp:Label runat="server" ID="lblDate"><%#Eval("Crea tionDate") %></asp:La bel></td>
<td><asp:Label runat="server" ID="lblSize"><%#Eval("Size ") %></asp:Label></td>
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr style="background-color:#E FEFEF">
<td>
<asp:LinkButton ID="lnkSelect" Text="ViewInstance" CommandName="Select" runat="server" />
</td>
<td><asp:Label runat="server" ID="lblId"><%#Eval("Histor yID") %></asp:Label></td>
<td><asp:Label runat="server" ID="lblDate"><%#Eval("Crea tionDate") %></asp:La bel></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("Histor yID") %></asp:Label></td>
<td><asp:Label runat="server" ID="lblDate"><%#Eval("Crea tionDate") %></asp:La bel></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
This is my firstListView,secondListVi
<asp:ListView ID="firstListView" runat="server" DataKeyNames="Path"
OnSelectedIndexChanging="f
<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
<td><asp:Label runat="server" ID="lblPath"><%#Eval("Path
<td><asp:Label runat="server" ID="lblType"><%#Eval("Modi
<td><asp:Label runat="server" ID="lblDate"><%#Eval("Type
<td><asp:Label runat="server" ID="Label1"><%#Eval("Modif
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr style="background-color:#E
<td>
<asp:LinkButton ID="lnkSelect" Text="History" CommandName="Select" runat="server" />
</td>
<td><asp:Label runat="server" ID="lblName"><%#Eval("Name
<td><asp:Label runat="server" ID="lblPath"><%#Eval("Path
<td><asp:Label runat="server" ID="lblType"><%#Eval("Modi
<td><asp:Label runat="server" ID="lblDate"><%#Eval("Type
<td><asp:Label runat="server" ID="Label1"><%#Eval("Modif
</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
<td><asp:Label runat="server" ID="lblPath"><%#Eval("Path
<td><asp:Label runat="server" ID="lblType"><%#Eval("Modi
<td><asp:Label runat="server" ID="lblDate"><%#Eval("Type
<td><asp:Label runat="server" ID="Label1"><%#Eval("Modif
</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="
<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="secondList
<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("Histor
<td><asp:Label runat="server" ID="lblDate"><%#Eval("Crea
<td><asp:Label runat="server" ID="lblSize"><%#Eval("Size
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr style="background-color:#E
<td>
<asp:LinkButton ID="lnkSelect" Text="ViewInstance" CommandName="Select" runat="server" />
</td>
<td><asp:Label runat="server" ID="lblId"><%#Eval("Histor
<td><asp:Label runat="server" ID="lblDate"><%#Eval("Crea
<td><asp:Label runat="server" ID="lblSize"><%#Eval("Size
</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("Histor
<td><asp:Label runat="server" ID="lblDate"><%#Eval("Crea
<td><asp:Label runat="server" ID="lblSize"><%#Eval("Size
</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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks
Is to bind the the 2nd listview to the first listview via the datakeyname