((TextBox)e.Item.Cells[i].Controls[0]).ID

解决方案 »

  1.   

    protected void DataGrid1_ItemDataBound(object sender, DataGridItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Header)
            {
                Response.Write(((TextBox)e.Item.Cells[0].Controls[1]).ID);
            }
        }
      

  2.   

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Header)
            {
                TextBox tb = (TextBox)this.GridView1.FindControl("TextBox1");
                Response.Write("'"+tb.Text+"'");
            }
        }
      

  3.   

    //按鈕裡讀取
    protected void Button1_Click(object sender, EventArgs e)
        {
            TextBox TextBox1 = (TextBox)DataGrid1.FindControl("dtg_00_ProdCode");
            Response.Write("'" +TextBox1.Text + "'");
        }
      

  4.   

    cpp2017(慕白兄) 
    是对的!支持
      

  5.   

    超级简单的问题。
    foreach (DataListItem dl in this.DataList1.Items)
            {         
               string date = ((TextBox)dl.FindControl("TextBox1")).ID;
                               
           }
      

  6.   

    谢谢慕白兄的回复,我现在想实现的功能是查出页面上所有的控件,对于页面上其他控件,比如:TextBox,Label等都已获得,就是对于datagrid中模版列中的控件不知如何得到,我现在将我的后台部分代码粘上开,麻烦帮我看看应该如何写?
     public void InitSystemTranslation(System.Web.UI.Page obj)
            {
                HtmlForm form = new HtmlForm();
                
                for (int i = 0; i < obj.Controls.Count; i++)
                {
                    if (obj.Controls[i] is HtmlForm)
                    {
                        form = obj.Controls[i] as HtmlForm;
                    }
                }
            foreach (object obj1 in form.Controls)
                {
                    if (obj1 is Panel)
                    {
                        foreach (object obj2 in (obj1 as Panel).Controls)
                        {
                            if (obj2 is Button)
                            {
                                Button Btn = obj2 as Button;
                            }
                            else if (obj2 is DataGrid)
                            {
                                DataGrid Dtg = obj2 as DataGrid;                            if (Dtg.ID.Length > 4 && Dtg.ID.Substring(Dtg.ID.Length - 4) == "Head")
                                {
                                    //如何写?
                                }
                            }
                            else if (obj2 is Label)
                            {
                                Label Lbl = obj2 as Label;                        }
                        }
                    }
                }
            }