<asp:TemplateField HeaderText="使用产品" ItemStyle-Width="150px">
   <ItemTemplate>
       <%#Eval("production")%>
   </ItemTemplate>
   <EditItemTemplate>
     <asp:Table runat="server" ID="productionTB" Width="150px"></asp:Table>
   </EditItemTemplate>
</asp:TemplateField>
我在GridView的一个cell里放了个table然后在后台给它添了值
((Table)(GridViewClient.Rows[e.NewEditIndex].Cells[7].Controls[1])).Rows.Add(tr);
但是在用的时候table里面为空了
Table tb = (Table)(GridViewClient.Rows[e.RowIndex].Cells[7].Controls[1]);
求正解啊

解决方案 »

  1.   

    ((Table)(GridViewClient.Rows[e.NewEditIndex].Cells[7].Controls[1])).Rows.Add(tr);这个位置放错了,放在RowDataBind事件里面
    if(e.Row.RowType == DataControlRowType.DataRow) {
                    if(e.Row.RowIndex == GridView1.EditIndex)
                    {
    ((Table)(GridViewClient.Rows[e.Row.RowIndex].Cells[7].Controls[1])).Rows.Add(tr);
    }Table tb = (Table)(GridViewClient.Rows[e.RowIndex].Cells[7].Controls[1]);
    在GridView1_RowUpdating事件中用
    处理写完后
    GridView1.EditIndex = -1;
                e.Cancel = true;处理下
      

  2.   

    ((Table)(GridViewClient.Rows[e.NewEditIndex].Cells[7].FildControl("tableid").Rows.Add(tr);Table tb = (Table)(GridViewClient.Rows[e.RowIndex].Cells[7].FildControl("tableid"));
      

  3.   

    添加行的时候需要先获取Table对象,然后创建行用 Table对象.NewRow
      

  4.   

    Table tb=GridViewClient.Rows[e.RowIndex].FindControl("") as Table;
      

  5.   

    ((Table)(GridViewClient.Rows[e.NewEditIndex].Cells[7].Controls[1])).Rows.Add(tr);
    这个我是放在GridViewClient_RowEditing里面的出这个事件时还是有值得
    等到了GridViewClient_RowUpdating就没值了
      

  6.   

    还是获取不到啊 关键是能获取到table但是table里面是没值得显示rows为空
      

  7.   

    Table tb=GridViewClient.Rows[e.RowIndex].FindControl("") as Table;
    根据.FindControl("") 先找出控件,然后再对他进行操作,
    ((Table)(GridViewClient.Rows[e.NewEditIndex].Cells[7].Controls[1])).Rows.Add(tr);
    Cells[7].Controls[1]))你这样写不能说不对,对着呢 但是这样写容易出错 建议你还是写全!
      

  8.   

    写全了 table也找到了 但是table是空的rows的count为0
      

  9.   

    Table tb=GridViewClient.Rows[e.RowIndex].FindControl("") as Table;
    根据.FindControl("") 先找出控件 再对他进行操作,
    ((Table)(GridViewClient.Rows[e.NewEditIndex].Cells[7].Controls[1])).Rows.Add(tr);
    Cells[7].Controls[1]))你这样写不能说不对  但是这样写容易出错 建议你还是写全!