我可以使用的FindControl一个数组? [英] Can I use an array in findcontrol?

查看:113
本文介绍了我可以使用的FindControl一个数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我有一个的DataList 有四个标贴,他们都最终以数字1-4。在我的code后面我有一个for循环,而且我想与设定的 Datalist中的标签数组。

Hello I have a DataList that has four lables and they all end with a number 1-4. In my code behind I have a for loop and an array that I want to set the labels of the Datalist with.

for (int x = 0; x< cartreciept.Items.Count; x++)
{
    DataListItem item = cartreceipt.Items[x];
    string catalogtype = ("select CatalogType From SC Where OrNum=" + OrNum)

    if (catalogtype="TC")
    {    
         ((Panel)item.FindControl("pnlIprintInfo")).Visible = true;
         string scRID = ("Select SCRID From SC Where OrNum =" + OrNum

        for(int y = 1; y<5; y++)
        {
              string lT[y] = (Select LineText From table Where SCartRD =" + scRID + " AND LN=" + y)

              ((Label)item.FindControl("lbl[y]")).text = lT[y];
        }
     }
} 

所以会在((标签)item.FindControl(LBL [Y]))工作?最该code的只是伪code,直到我图的细节出来。如果你需要知道什么我可以提供需要知道什么,我接受其他的建议为好。谢谢你对任何一个谁可以提供一些帮助。

So would the ((Label)item.FindControl("lbl[y]")) work? most of this code is just pseudo code until I figure the details out. If you need to know anything else I can provide what needs to be known, I am open to other suggestions as well. Thank you to any one who can offer some help.

推荐答案

您可以使用此code - 基于的String.Format(...... {0}参数)

You can use this code - based on string.Format("....{0}",arguments)

var control = (Label)item.FindControl(string.Format("lbl{0}",y));

我建议你使用 DataList.ItemDataBound

链接:http://msdn.microsoft.com/fr-fr/library/system.web.ui.webcontrols.datalist.itemdatabound.aspx

这篇关于我可以使用的FindControl一个数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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