private void ◆dg_ItemCreated(object sender, e)
{
if(e.Item.ItemType == ListItemType.Footer )
{
e.Item.Cells[0].Text="增 加:"; for (int i=1;i <= e.Item.Cells.Count - 1;i++)
{
foreach(DataGridItem dgi in MyDataGrid.Items)
                     {
                       TextBox txtInfo=(LinkButton)dgi.FindControl("你要获取的TextBox的ID");
     txtInfo.ID="txtInfo" + i.ToString();
                       if (txtInfo!= null)
     ◆e.Item.Cells[i].Controls.Add(txtInfo);
   }
}

}

解决方案 »

  1.   

    这个
    private void ◆dg_ItemCreated(object sender, e)
    {
    if(e.Item.ItemType == ListItemType.Footer )
    {
    e.Item.Cells[0].Text="增 加:"; for (int i=1;i <= e.Item.Cells.Count - 1;i++)
    {
    foreach(DataGridItem dgi in MyDataGrid.Items)
                         {
                           TextBox txtInfo=(LinkButton)dgi.FindControl("你要获取的TextBox的ID");
         if (txtInfo!= null)
                             {
                               txtInfo.ID="txtInfo" + i.ToString();         ◆e.Item.Cells[i].Controls.Add(txtInfo);
                             }
       }
    }

    }
      

  2.   

    DataGrid1_ItemDataBound(
    If (e.Item.ItemType = ListItemType.Footer) Then
                CType(e.Item.FindControl("Button9"), Button).Enabled = False
            End If
      

  3.   

    在DataGrid外的一个按钮事件里能获取到吗?
      

  4.   

    TextBox txt = (TextBox)e.Item.Cell[i]Controls[0];
    txt就是你要找的TextBox,可以得到他们所有属性。
      

  5.   

    private void btnSave_Click(object sender, System.EventArgs e)
    {
    TextBox tb = (TextBox)dg.FindControl("txtInfo1"); Response.Write(tb.Text);
    }
    怎么不对呢?
      

  6.   

    应该遍历一下你的DataGrid
    foreach(DataGridItem dgi in MyDataGrid.Items)
                         {
                         TextBox tb = (TextBox)dg.FindControl("txtInfo1"); Response.Write(tb.Text);
       }
      

  7.   

    DataGrid.Items集合并不包含 Header和Footer部分,但是在DataGrid.Controls集合中包含这两部分,因此用如下方法,如有不明白可以将page指令trace 设为true看一下控件树的层次关系和UniqueID:
    假设DataGrid名为dgControl table=dg.Controls[dg.Controls.Count-1];
    DataGridItem item=(DataGridItem)table.Controls[table.Controls.Count-1];这样item就是footer,类型为DataGridItem,这样引用item就可以像其它地方一样访问了,例如输出footer的第一列:
    Response.Write(item.Cells[0].Text)。