Hide and show controls in a ListView's ItemTemplate

Is it possible in a ListView's ItemTemplate to reference a Label in code-behind onload or method?  I want to make visible dynamically each Label control based on my column count of my dataset.
ws11Asked:
Who is Participating?
 
guru_samiConnect With a Mentor Commented:
you can use LV ItemDataBound event and do something like this:
Label lbl = e.Item.FindControl("Lable1");
if(lbl!=null)
{ lbl.visible = true or false based on some condition
}
Or post your lv code and with more info on what you are looking for...
0
 
ws11Author Commented:
Thanks I realized that this might not be the what I really need.  My item template is a table with the labels filling the td tags.  I also need to dynamically handle each td.  So to be more specific the user will be  importing an excel sheet with an unknown number of columns.  I am currently showing the records in a listview from a sql table that the excel was imported to.  Next I need to allow the user to define each column from a drop down list since each user may have there own proprietary structure in the excel file.  
0
 
ws11Author Commented:
I think I will submit this in a different question.  You accurately answered my question.  Thanks.
0
 
ws11Author Commented:
Is it possible to do something like article ID: 21113426 and place it inside the layout template or item template?

call in code-behind

dynamicTable = Build_Dynamic_Table();


<LayoutTemplate>
    <div class="lvBackground">
    <asp:Table id="dynamicTable" runat="server" />
    </div>
</LayoutTemplate>

or

<ItemTemplate>
    <div class="lvBackground">
    <asp:Table id="dynamicTable" runat="server" />
    </div>
</ItemTemplate>

protected Table Build_Dynamic_Table()
    {
        Table tDynamicTable;
        TableRow trRow;
        TableCell tcCell;

        tDynamicTable = new Table();

        for (int y = 1; y <= 10; y++)
        {
            trRow = new TableRow();
            for (int x = 1; x <= 5; x++)
            {
                tcCell = new TableCell();
                tcCell.Text = "Add text here";
                trRow.Cells.Add(tcCell);
            }

            tDynamicTable.Rows.Add(trRow);
        }

        return tDynamicTable;
    }

Open in new window

0
All Courses

From novice to tech pro — start learning today.