如何访问listview控件的标签控件? [英] How do I access label control of a listview control?

查看:75
本文介绍了如何访问listview控件的标签控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在嵌套listview中我有标签,我想访问file.ow后面的代码我能做到吗?请帮我。我想显示几个标签并隐藏几个标签



我尝试过:



< tbody id =divcomprunat =server> ;

< asp:ListView ID =ddlcomputersrunat =serverDataKeyNames =CidOnItemCommand =ddlcomputers_ItemCommandOnItemDeleted =ddlcomputers_ItemDeleted>

< br $> b $ b

< asp:标签ID =lblComputerNameerunat =serverText ='<%#Eval(ComputerName)%>'>

< img class =md-triggerdata-modal ='<%#Eval(ComputerName)%>'align =absmiddlesrc =../ html / images /info.pngrunat =serverwidth =24height =24alt =/>

< asp:Label ID =lblCidrunat =server Text ='<%#Eval(Cid)%>'Visible =false>

< asp:ListView ID =ListView1runat =server> < br $>










电脑详情







电脑名称:

<%#Eval(ComputerName)%>





IP地址:

<%#Eval(IPAddress)%>





电脑类型:

< ;%#Eval(ComputerType)%>









部门:

<%#Eval(部门)%>









Smps:

<%#Eval(Cpu)%>





处理器:

<%#Eval(处理器)%>





Ram:

<%#Eval(Ram)%>





董事会:

<%#Eval(Board)%>





HardDisk:

<%#Eval(HardDisk)%>





鼠标:

<%#Eval(鼠标)%>





KeyBoard:

<%#Eval(键盘)%>





显示器:

< ;%#Eval(监控)%>



状态:

<%#Eval(状态)%> ;



日期:

<%#Eval(日期)%>



WhoBrought:

<%#Eval(WhoBrought)%>



谁添加:

<%#Eval(WhoAdded)%>



< button class =md-close>< / button> ;









<%#Eval(ComputerType )%> < asp:ImageButton ID =imgeditrunat =serverImageUrl =〜/ html / images / edit.pngWidth =24CommandName =EditHeight =24alt =/> < asp:ImageButton ID =imgrepairrunat =serverImageUrl =〜/ html / images / repair.pngWidth =24Height =24CommandName =Repairalt =/> < asp:ImageButton ID =imgdelrunat =serverImageUrl =〜/ @@@ html / images / Dead.jpgWidth =24Height =24alt =CommandName =Dead OnClientClick =返回确认('你想要死这台电脑吗?'); /> < td runat =servervisible =false>

< asp:ImageButton ID =ImageButton1runat =serverImageUrl =〜/ html / images / delete.png Width =24Height =24alt =CommandName =DeleteOnClientClick =return confirm('你想删除这台电脑吗?'); />

< asp:标签ID =LblOtherrunat =serverText ='<%#Eval(Status)%>'>

in nested listview i have labels and i want to acces in code behind file.how can i do that?please help me out.i want to display few labels and hide few labels in that

What I have tried:

<tbody id="divcomp" runat="server">
<asp:ListView ID="ddlcomputers" runat="server" DataKeyNames="Cid" OnItemCommand="ddlcomputers_ItemCommand" OnItemDeleted="ddlcomputers_ItemDeleted">


<asp:Label ID="lblComputerNamee" runat="server" Text='<%#Eval("ComputerName") %>'>
<img class="md-trigger" data-modal='<%#Eval("ComputerName") %>' align="absmiddle" src="../html/images/info.png" runat="server" width="24" height="24" alt="" />
<asp:Label ID="lblCid" runat="server" Text='<%#Eval("Cid") %>' Visible="false">
<asp:ListView ID="ListView1" runat="server">





Computer Details



Computer Name :
<%#Eval("ComputerName") %>


IP Address :
<%#Eval("IPAddress") %>


Computer Type :
<%#Eval("ComputerType") %>




Department :
<%#Eval("Department") %>




Smps :
<%#Eval("Cpu") %>


Processor :
<%#Eval("Processor") %>


Ram :
<%#Eval("Ram") %>


Board :
<%#Eval("Board") %>


HardDisk :
<%#Eval("HardDisk") %>


Mouse :
<%#Eval("Mouse") %>


KeyBoard :
<%#Eval("Keyboard") %>


Monitor :
<%#Eval("Monitor") %>

Status:
<%#Eval("Status") %>

Date:
<%#Eval("Date") %>

WhoBrought :
<%#Eval("WhoBrought") %>

WhoAdded :
<%#Eval("WhoAdded") %>

<button class="md-close"></button>




<%#Eval("ComputerType") %> <asp:ImageButton ID="imgedit" runat="server" ImageUrl="~/html/images/edit.png" Width="24" CommandName="Edit" Height="24" alt="" /> <asp:ImageButton ID="imgrepair" runat="server" ImageUrl="~/html/images/repair.png" Width="24" Height="24" CommandName="Repair" alt="" /> <asp:ImageButton ID="imgdel" runat="server" ImageUrl="~/@@@html/images/Dead.jpg" Width="24" Height="24" alt="" CommandName="Dead" OnClientClick="return confirm('Do you want to Dead this Computer?');" /> <td runat="server" visible="false">
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/html/images/delete.png" Width="24" Height="24" alt="" CommandName="Delete" OnClientClick="return confirm('Do you want to delete this Computer?');" />
<asp:Label ID="LblOther" runat="server" Text='<%#Eval("Status") %>'>

推荐答案

<asp:ListView id="MyListView" runat="server">
    <ItemTemplate>
        <asp:Label ID="MyLabel" runat="server" Text='<%#Eval("Name")%>' />
    </ItemTemplate>
</asp:ListView>







protected void Page_Load(object sender, EventArgs e)
{
    MyListView.DataSource = new List<MyData> { new MyData { Name = "John" }, new MyData { Name = "David" } };
    MyListView.DataBind();

    foreach (ListViewDataItem item in MyListView.Items)
    {
        Label l = (Label)item.FindControl("MyLabel");
        l.Text = l.Text.ToUpper();
    }
}


这篇关于如何访问listview控件的标签控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆