M
Mario
I need to pick up the "TotalItemsLabel" text in my C# method. How to do
that if this is the part of my Default.aspx page which is generated from
master page:
...
<asp:ListView ID="ListView1" runat="server" DataKeyNames="ID"
DataSourceID="ObjectDataSourceNarudzba"
...
<LayoutTemplate>
<table id="Table2" runat="server">
<tr id="Tr1" runat="server">
<td id="Td1" runat="server">
<table id="itemPlaceholderContainer"
runat="server" border="1" style="background-color: #FFFFFF;
border-collapse: collapse;
border-color: #999999; border-style: none; border-width: 1px;
font-family: Verdana, Arial,
Helvetica, sans-serif;">
<tr id="Tr2" runat="server"
style="background-color: #FFFBD6; color: #333333;">
<th id="Th1" runat="server">
</th>
<th id="Th2" runat="server">
</th>
<th id="Th3" runat="server">
TEKST
</th>
<th id="Th4" runat="server">
OPIS
</th>
</tr>
<tr id="itemPlaceholder"
runat="server">
</tr>
</table>
</td>
</tr>
<tr id="Tr3" runat="server">
<td id="Td2" runat="server"
style="text-align: center; background-color: #FFCC66;
font-family: Verdana, Arial, Helvetica,
sans-serif; color: #333333;">
<aspataPager ID="DataPager1"
runat="server" PageSize="4">
<Fields>
<asp:NextPreviousPagerField
ButtonType="Button" ShowFirstPageButton="True" ShowLastPageButton="True" />
<asp:TemplatePagerField>
<PagerTemplate>
<b>stranica:
<asp:Label
runat="server" ID="CurrentPageLabel" Text="<%# Container.StartRowIndex
%>" />
od
<asp:Label
runat="server" ID="TotalPagesLabel" Text="<%#
Container.StartRowIndex+Container.PageSize %>" />
(ukupno
<asp:Label
runat="server" ID="TotalItemsLabel" Text="<%# Container.TotalRowCount%>" />
zapisa)
<br />
</b>
</PagerTemplate>
</asp:TemplatePagerField>
</Fields>
</aspataPager>
</td>
</tr>
</table>
</LayoutTemplate>
...
</asp:ListView>
I tried like this:
Label x =
(Label)ListView1.InsertItem.FindControl("DataPager1").FindControl("TotalItemsLabel");
but I got: Object reference not set to an instance of an object
I also tried:
DataPager y=
(DataPager)ListView1.InsertItem.FindControl("DataPager1");
Got the same error.
Finaly I tried to Find all IDs from ListView to DataPager:
DataPager stranicnik =
(DataPager)ListView1.InsertItem.FindControl("Table2").FindControl("Tr3").FindControl("Td2").FindControl("DataPager1");
//count = stranicnik.TotalRowCount;
//pageSize = stranicnik.PageSize;
And again got the same error.
How to find DataPager control to get the TotalRowCount, which is works
perfectly on my aspx page? Or how to Find that specific label ?
All that I tried within C# method ListView1_DataBound
that if this is the part of my Default.aspx page which is generated from
master page:
...
<asp:ListView ID="ListView1" runat="server" DataKeyNames="ID"
DataSourceID="ObjectDataSourceNarudzba"
...
<LayoutTemplate>
<table id="Table2" runat="server">
<tr id="Tr1" runat="server">
<td id="Td1" runat="server">
<table id="itemPlaceholderContainer"
runat="server" border="1" style="background-color: #FFFFFF;
border-collapse: collapse;
border-color: #999999; border-style: none; border-width: 1px;
font-family: Verdana, Arial,
Helvetica, sans-serif;">
<tr id="Tr2" runat="server"
style="background-color: #FFFBD6; color: #333333;">
<th id="Th1" runat="server">
</th>
<th id="Th2" runat="server">
</th>
<th id="Th3" runat="server">
TEKST
</th>
<th id="Th4" runat="server">
OPIS
</th>
</tr>
<tr id="itemPlaceholder"
runat="server">
</tr>
</table>
</td>
</tr>
<tr id="Tr3" runat="server">
<td id="Td2" runat="server"
style="text-align: center; background-color: #FFCC66;
font-family: Verdana, Arial, Helvetica,
sans-serif; color: #333333;">
<aspataPager ID="DataPager1"
runat="server" PageSize="4">
<Fields>
<asp:NextPreviousPagerField
ButtonType="Button" ShowFirstPageButton="True" ShowLastPageButton="True" />
<asp:TemplatePagerField>
<PagerTemplate>
<b>stranica:
<asp:Label
runat="server" ID="CurrentPageLabel" Text="<%# Container.StartRowIndex
%>" />
od
<asp:Label
runat="server" ID="TotalPagesLabel" Text="<%#
Container.StartRowIndex+Container.PageSize %>" />
(ukupno
<asp:Label
runat="server" ID="TotalItemsLabel" Text="<%# Container.TotalRowCount%>" />
zapisa)
<br />
</b>
</PagerTemplate>
</asp:TemplatePagerField>
</Fields>
</aspataPager>
</td>
</tr>
</table>
</LayoutTemplate>
...
</asp:ListView>
I tried like this:
Label x =
(Label)ListView1.InsertItem.FindControl("DataPager1").FindControl("TotalItemsLabel");
but I got: Object reference not set to an instance of an object
I also tried:
DataPager y=
(DataPager)ListView1.InsertItem.FindControl("DataPager1");
Got the same error.
Finaly I tried to Find all IDs from ListView to DataPager:
DataPager stranicnik =
(DataPager)ListView1.InsertItem.FindControl("Table2").FindControl("Tr3").FindControl("Td2").FindControl("DataPager1");
//count = stranicnik.TotalRowCount;
//pageSize = stranicnik.PageSize;
And again got the same error.
How to find DataPager control to get the TotalRowCount, which is works
perfectly on my aspx page? Or how to Find that specific label ?
All that I tried within C# method ListView1_DataBound