如何在代码中找到cotrol div [英] How to find cotrol div in code behind

查看:70
本文介绍了如何在代码中找到cotrol div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的div在转发器中,



请让我知道如何在代码中找到控制div

my div is in repeater ,

Please Let me know how to findcontrol div in code behind

推荐答案

你需要遍历转发器然后获取div的id ...确保在div中添加runat = server



u need to loop through the repeater and then get the id of the div... make sure to add runat=server in the div

foreach (RepeaterItem item in rptItems.Items)
{
    if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
    {
        System.Web.UI.HtmlControls.HtmlGenericControl yourDiv= (System.Web.UI.HtmlControls.HtmlGenericControl)item.FindControl("yourDiv");

        //Do something with your yourDiv...

    }
}


试试这个朋友.......



------------

Aspx页面

------------
Try this one friend.......

------------
Aspx Page
------------


< asp:label id =_ lblrunat =servertext =检查xmlns:asp =#unknown> ;

< asp:button id =_ btnrunat =servertext =Hit ...onclick =_ btn_Clickxmlns:asp =#unknown>


<asp:label id="_lbl" runat="server" text="Check" xmlns:asp="#unknown">
<asp:button id="_btn" runat="server" text="Hit..." onclick="_btn_Click" xmlns:asp="#unknown">







------------

代码隐藏.cs文件找到控件

------------



protected void _btn_Click (对象发送者,EventArgs e)

{

标签lbl =(标签)_d.FindControl(_ lbl);

lbl.Text =Hiiiiiiiiiiiiiiiii;

}



享受解决方案:):)):)........




------------
Code Behind .cs file which find control
------------

protected void _btn_Click(object sender, EventArgs e)
{
Label lbl=(Label)_d.FindControl("_lbl");
lbl.Text = "Hiiiiiiiiiiiiiiiii";
}

Enjoy solution :):):)........


这篇关于如何在代码中找到cotrol div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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