找到ListView控件 [英] find control in listview

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

问题描述

通过在GridView的pressing按钮,我需要找到在列表视图控制。

 <&ItemTemplate中GT;
&所述; TD>    < ASP:标签ID =lblMarketLVBalanceHeader=服务器文本=余额:>< / ASP:标签>
< / TD>
&所述; TD>
    < ASP:标签ID =lblMarketLVBalanceValue=服务器文本='<%#绑定(金钱,{0:####} $)%>'>< / ASP :标签>< / TD>< / ItemTemplate中>

code背后:

 保护无效GVMarketItems_RowCommand(对象发件人,GridViewCommandEventArgs E)
    {
如果(e.CommandName.Equals(买入))
        {GridViewRow行=(GridViewRow)(((按钮)e.CommandSource).NamingContainer);
         / *字符串ITEMID = row.Cells [0]。文本;
           字符串ITEMNAME = row.Cells [1]。文本;
           串itemCostStr = row.Cells [3]。文本; * /
 字符串curBalanceStr =((标签)LVMarketBalanceShow.FindControl(lblMarketLVBalanceValue))文本。
}

code似乎找到,但我有当我试图找到控制对象引用不设置到对象的实例。

 字符串curBalanceStr =((标签)LVMarketBalanceShow.FindControl(lblMarketLVBalanceValue))文本。

做了同样到DetailsView控件,它是确定..有什么不对的ListView?

UPD:试图让列表视图的第一FOW

  ListViewDataItem curBalanceLV = LVMarketBalanceShow.Items [0];
       字符串curBalanceStr =((标签)curBalanceLV.FindControl(lblMarketLVBalanceValue))文本。

但得到一个错误索引超出范围。


解决方案

  

做了同样到DetailsView控件,它是确定..这有什么错
  ListView的?


一个DetailsView控件用于同时与一排,以解决这样你就可以直接调用的FindControl()在DetailsView控件,但GridView和ListView控件是为了显示多个记录你的标记,你在&LT定义; ItemTemplate中/> 仅仅是各行的模板。你就可以发现你在模板中定义每一行的内部控制。

By pressing button in GridView i need to find control in Listview.

<ItemTemplate>
<td>

    <asp:Label ID="lblMarketLVBalanceHeader" runat="server" Text="Balance: "></asp:Label>
</td>


<td>
    <asp:Label ID="lblMarketLVBalanceValue" runat="server" Text='<%# Bind("Money", "{0:####}$") %>'></asp:Label>

</td>

</ItemTemplate>

Code Behind:

protected void GVMarketItems_RowCommand(object sender, GridViewCommandEventArgs e)
    {
if (e.CommandName.Equals("Buy"))
        {  GridViewRow row = (GridViewRow)(((Button)e.CommandSource).NamingContainer);
         /*  string itemID = row.Cells[0].Text;
           string itemName = row.Cells[1].Text;
           string itemCostStr = row.Cells[3].Text; */
 string curBalanceStr = ((Label)LVMarketBalanceShow.FindControl("lblMarketLVBalanceValue")).Text;
}

Code seems find, but i have "Object reference not set to an instance of an object" when i'm trying to Find control.

string curBalanceStr = ((Label)LVMarketBalanceShow.FindControl("lblMarketLVBalanceValue")).Text;

Did the same to DetailsView and it was Ok.. What's wrong with ListView?

UPD: Trying to get first fow of listview

ListViewDataItem curBalanceLV = LVMarketBalanceShow.Items[0];
       string curBalanceStr =((Label)curBalanceLV.FindControl("lblMarketLVBalanceValue")).Text;

But getting an error "Index was out of range."

解决方案

Did the same to DetailsView and it was Ok.. What's wrong with ListView?

A DetailsView is used to tackle with one row at a time so you can directly call FindControl() on the detailsview but gridview and listview are meant to display multiple records and your markup you define inside <ItemTemplate /> is just a template for each row. You'll be able to find the controls that you define in the template inside of each row.

这篇关于找到ListView控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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