2

I have a listview control that is nested in the item template of another listview control that i'm trying to reference in codebehind using the .FindControl() method, but it keeps returning null. After get this to work, I'll need to reference a ComboBox inside of the inner listview. Here is where I am so far:

ListView lsvTickets
   ItemTemplate
        Listview lsvActions
             ItemTemplate
                  ComboBox cboAssignees

I'm using the following code to attempt the reference in code behind:

var actions = (RadListView)lsvTickets.FindControl("lsvActions");

But this is returning null. I thought I would only have to do something like this to achieve the final desired result:

var assignees = (RadComboBox)lsvTickets.FindControl("lsvActions").FindControl("cboAssignees")

Can anyone help? What am I doing wrong here? Here's the full layout for those of you it would help:

<rad:RadListView runat="server" ID="lsvTickets">
        <ItemTemplate>
            <div id="divContainer" class="divContainer">
                <div id="divTicketHeader" class="divTicketHeader">
                    <asp:Table runat="server" ID="tblTicketHead" Width="100%" CellSpacing="0" CellPadding="5" HorizontalAlign="Center">
                        <asp:TableRow HorizontalAlign="Center">
                            <asp:TableCell  Width="25%">
                                <asp:Label ID="Label1" runat="server" Text='<%#Eval("Subject") %>' Font-Bold="true" />
                            </asp:TableCell><asp:TableCell Width="25%">
                                <asp:Label ID="Label2" runat="server" Text='<%#Eval("Status.Key") %>' />
                            </asp:TableCell><asp:TableCell Width="25%">
                                <asp:Label ID="Label3" runat="server" Text='<%#Eval("Ticket.Reported_By") %>' />
                            </asp:TableCell><asp:TableCell Width="25%">
                                <asp:Label ID="Label4" runat="server" Text='<%#Eval("DateOpened") %>' />
                            </asp:TableCell></asp:TableRow></asp:Table></div>
                    <div id="divTicketBody" class="divComments">
                        <rad:RadListView runat="server" ID="lsvActions" DataSource='<%#Eval("TicketActions") %>'>
                            <ItemTemplate>
                                <center>                            
                                <div id="divAddComment" style="width: 500px;">
                                    <div id="divCommentControls" style="margin: 8px 0px 8px 0px;">
                                        <rad:RadComboBox runat="server" ID="cboStatus" DataSource='<%#GetStatuses() %>' DataTextField="Status" DataValueField="ID" />                                            <rad:RadComboBox runat="server" ID="cboAssignTo" DataSource='<%#GetAssignees() %>' DataTextField="Key" DataValueField="Value" />
                                    </div>
                                    <rad:RadTextBox runat="server" ID="txtComment" TextMode="MultiLine" Width="500" Height="100" CssClass="commentBox" /><br />
                                    <div style="height: 35px;">
                                        <div style="float:left"><asp:CheckBox ID="cbMakeITTicket" runat="server" Text="Convert to IT Support Ticket" /></div>
                                        <div style="float:right; margin: 3px 0 0 0; "><rad:RadButton runat="server" ID="btnSubmit" Text="Submit" CssClass="buttonTag" /></div>
                                    </div>
                                </div>
                                </center>
                                <div id="divComment" class="divComment">
                                    <asp:Table runat="server" ID="tblComment" CellPadding="5">
                                        <asp:TableRow>
                                            <asp:TableCell Width="15%" HorizontalAlign="Center">
                                                <rad:RadBinaryImage runat="server" ID="imgCommenter" Width="50" Height="50" /><br />
                                                <asp:Label ID="Label5" runat="server" Text="[action author]" CssClass="commenterText" /><br />
                                                <asp:Label ID="Label6" runat="server" Text='<%#Eval("Action_Date", "{0:MMM d, yyy hh:mm}") %>'
                                                     CssClass="commenterText"/><br />
                                            </asp:TableCell><asp:TableCell>
                                                <asp:Label ID="Label7" runat="server" Text='<%#Eval("Description") %>' />
                                            </asp:TableCell>
                                        </asp:TableRow>
                                    </asp:Table>
                                </div>
                            </ItemTemplate>
                        </rad:RadListView>
                    </div>
            </div>
        </ItemTemplate>
    </rad:RadListView>
</asp:Content>
Sinaesthetic
  • 9,847
  • 25
  • 95
  • 165

1 Answers1

1

You're looking for a combobox in a control that potentially has many lines (thus rows of combobox instances ) - it doesn’t know which one you’re looking for.

Obviously I don’t know what you need to do to the combobox but you should look at alternate approaches. Take a look at using the OnItemDataBound event of lsvActions

Then add code such as …

protected void lsvActions_ItemDataBound(object sender, GridItemEventArgs e)
        {


            if (e.Item is GridDataItem)
            {
                GridDataItem item = (GridDataItem)e.Item;
                RadComboBox  myCBO = (RadComboBox)item.FindControl("cboStatus")

                myCBO.Visible = false;

            }
}

...also, just a general tip, I usually find using OnNeedDataSource to load RadGrids and ListViews saves a lot of headaches.

Hope that helps.

neverwinter
  • 804
  • 2
  • 15
  • 39
Eamon
  • 246
  • 2
  • 5