This is a migrated thread and some comments may be shown as answers.

FindControl

3 Answers 213 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Neil
Top achievements
Rank 1
Neil asked on 09 Jun 2010, 07:36 PM
I am trying to hide the DataPager if not results are being returned.  Here is my markup:

<telerik:RadListView ID="ProductResults" Width="100%" AllowPaging="True" runat="server" AllowSorting="true" ItemPlaceholderID="ProductsHolder" DataKeyNames="Key.Id"
            <LayoutTemplate> 
                <div class="PagingContainer" id="RadListView1"
                    <asp:Panel ID="ProductsHolder" runat="server" /> 
                    <asp:Panel ID="PagingPanel" runat="server"
                        <div id="Paging" runat="server" style="float: left; clear: both;"
                        <telerik:RadDataPager Skin="Default" AllowSEOPaging="true" SEOPagingQueryPageKey="page" 
                            Font-Bold="false" BackColor="#FFFFFF" BorderColor="#FFFFFF" ID="ProductResultsPager" 
                            runat="server" PagedControlID="ProductResults" PageSize="12"
                            <Fields> 
                                <telerik:RadDataPagerButtonField FieldType="FirstPrev" /> 
                                <telerik:RadDataPagerButtonField FieldType="Numeric" /> 
                                <telerik:RadDataPagerButtonField FieldType="NextLast" /> 
                                <telerik:RadDataPagerTemplatePageField> 
                                    <PagerTemplate> 
                                        <div style="float: right; text-align: right; font-family: Arial;"
                                            <b>Products 
                                                <asp:Label runat="server" ID="CurrentPageLabel" Text="<%# Container.Owner.StartRowIndex+1%>" /> 
                                                to 
                                                <asp:Label runat="server" ID="TotalPagesLabel" Text="<%# Container.Owner.StartRowIndex+Container.Owner.PageSize %>" /> 
                                                of 
                                                <asp:Label runat="server" ID="TotalItemsLabel" Text="<%# Container.Owner.TotalRowCount%>" /> 
                                                <br /> 
                                            </b> 
                                        </div> 
                                    </PagerTemplate> 
                                </telerik:RadDataPagerTemplatePageField> 
                            </Fields> 
                        </telerik:RadDataPager> 
                    </div> 
                    </asp:Panel> 
                </div> 
            </LayoutTemplate> 
            <ItemTemplate> 
                <div class="itemPicker" style="float: left; height: 75px; width: 215px; margin: 7px; padding: 10px 5px 10px 5px; border: solid 1px #ccc;"
                    <div style="width: 75px; float: left; margin: 0 0 0 5px;"
                        <id="ProductImageLink" runat="server"
                            <img border="0" src="<%# Eval("Value")%>"></a> 
                    </div> 
                    <div style="width: 120px; float: left; padding-left: 10px;"
                        <id="ProductLink" class="ProductSearchGridResultTitle" runat="server"
                            <%# Eval("Key.Title")%> 
                        </a> 
                    </div> 
                </div> 
            </ItemTemplate> 
        </telerik:RadListView> 

I am using FindControl to get access to the DataPager, and when I step through my code, and value.count  is 0, I get a null exception  on dataPager:

if (value.Count == 0) 
                { 
                    NoResults.Visible = true
                    RadDataPager dataPager = (RadDataPager)ProductResults.FindControl("ProductResultsPager"); 
                    dataPager.Visible = false
                } 

Ideas?

Thanks in advance!




3 Answers, 1 is accepted

Sort by
0
Neil
Top achievements
Rank 1
answered on 10 Jun 2010, 03:42 PM
By adding FindingControl in a LayoutCreated event, I was able to hide the control.

protected void ProductResults_LayoutCreated(object sender, EventArgs e) 
        { 
 
            if (ProductCountLiteral.Text == "0"
                ((RadDataPager)ProductResults.FindControl("ProductResultsPager")).Visible = false
        } 

0
Pams
Top achievements
Rank 1
answered on 12 Oct 2010, 01:23 PM
Hello,
I have problem with finding controls
I have a radgrid with several columns.
And one column has gridtemplatecolumn. In the item template of grid template column i am having Radlistview. 
My reqirement is I need to place a list of images in that colmn for each row. The nmber of images vary depending on the row id.
So, I though of using Radlistview in the Itemtemplate of gridtemplatecolumn.
<telerik:GridTemplateColumn UniqueName="DocumentStatus_Template">
    <HeaderTemplate>
     <label id="status">
         Document Status</label>
         </HeaderTemplate>
 <ItemTemplate>
<telerik:RadListView ID="DocumentStatusRadListView" runat="server" 
                         ItemPlaceholderID="DocumentStatusContainerPanel" >
                            <LayoutTemplate>
                                <asp:Panel ID="DocumentStatusContainerPanel" runat="server">
                                </asp:Panel>
                            </LayoutTemplate>
                            <ItemTemplate>                            
                                <div class="Stacked">                                  
                                    <asp:Image ID="StatusImg" runat="server" />                               
                                </div>                                
                            </ItemTemplate>
</telerik:RadListView>
</ItemTemplate>
</telerik:GridTemplateColumn>

I get the data from database in the code behind and I am planning to bind the images for each row in the code behind.
I will check the data of radgrid for each row and accordingly I have to bind the images. ( we have total of 5 images).
But each row may contain any number from 1 to 5.
 Bt the problem is I am not able to get the Image ID in code behind so that I can give the image url.

   var listView = (item["DocumentStatus_Template"].FindControl("DocumentStatusRadListView") as RadListView);

Is this right way to do. Or is there a better way to proceed
Can I have a code snnippet.

Thanks in advance
0
Pavlina
Telerik team
answered on 14 Oct 2010, 11:53 AM
Hi Pams,

Please examine this article:
Accessing cells and rows

Greetings,
Pavlina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
ListView
Asked by
Neil
Top achievements
Rank 1
Answers by
Neil
Top achievements
Rank 1
Pams
Top achievements
Rank 1
Pavlina
Telerik team
Share this question
or