本文介绍了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

推荐答案

#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,LoadTemplate,如何通过FindControl获得控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 13:13