FormView,LoadTemplate,如何通过FindControl获得控制 [英] FormView ,LoadTemplate, how to get control by FindControl

查看:84
本文介绍了FormView,LoadTemplate,如何通过FindControl获得控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

FormView问题:

我的用户:

A FormView question:

i user :

FormView1.ItemTemplate = LoadTemplate("FormView.ascx");


FormView.ascx:


FormView.ascx:

<asp:textbox id="textbox" runat="server" text="This is a test" xmlns:asp="#unknown"></asp:textbox>





protected void FormView1_DataBound(object sender, EventArgs e)
{
  // how to get thi control "textbox"  by FindControl?

}



谢谢



thank you

推荐答案

我写了一个函数来在formview中找到控件:

i write a function to find a control in formview:

#region       
        protected Control GetControlOfFormView(FormView fv, string strControlID)
        {
            Control ctl = new Control();
            FormViewRow fvr = fv.Row;
            TableCell tc = new TableCell();
            Control CellCtl = new Control();
            int nCell,nCellCtl;
            int j, k;
            nCell = fvr.Cells.Count;
            for (j = 0; j < nCell; j++)
            {
                tc = fvr.Cells[j];
                nCellCtl = tc.Controls.Count;
                for (k = 0; k < nCellCtl; k++)
                {
                    CellCtl = tc.Controls[k];
                    ctl = CellCtl.FindControl(strControlID);
                    if (ctl != null)
                    {
                        k = nCellCtl;
                        j = nCell;
                    }
                }
            }
            return ctl;
        }
        #endregion



使用它:



use it :

protected void FormView1_DataBound(object sender, EventArgs e)
{
   DataRowView row = (DataRowView)FormView1.DataItem;
   TextBox tb = null;

   tb = (TextBox)GetControlOfFormView(FormView1, "textbox");
   tb.Text = row["Bsf_FormID"].ToString();
}



谢谢erveryone,如果有个好主意,我想知道你怎么做.谢谢



thanks erveryone, if have good idea ,i want to know how you do it.thanks


发件人不过是Formview控件而已,它只是在项目中循环并获取文本框

问候
Vinay
The sender is nothing but the Formview control it self just loop through the items and get the text box

Regards
Vinay


我想为id ="textbox"设置一个值,怎么办?
I want to set a value to id="textbox" ,how to do ?


这篇关于FormView,LoadTemplate,如何通过FindControl获得控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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