以前在datagrid的编辑事件中,是这样获取修改后的数据的。 
string aa=((TextBox)(e.Item.Cell[2].Controls[0])).Text; 想请问各位高手在vs2005要怎样写这个语句呢?谢谢!

解决方案 »

  1.   

    string stuName = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtName")).Text;
                        类型                                                    名
      

  2.   

    TextBox是类型txtName是列名                        <asp:TemplateField HeaderText="姓名">
                                <EditItemTemplate>
                                    <asp:TextBox ID="txtName" Width=35 runat="server" Text='<%# Eval("stuName") %>'></asp:TextBox>
                                </EditItemTemplate>                            <ItemTemplate>
                                    <asp:Label ID="Label2" runat="server"><%# Eval("stuName") %></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
      

  3.   

    string aa=((TextBox)(e.Item.Cell[2].Controls[0])).Text;  
    ==
    string aa=((TextBox)(e.Row.Cell[2].Controls[0])).Text;  不过强烈建议使用FindControl找到控件
      

  4.   

    TextBox tb= GridView1.Rows[e.RowIndex].FindControl("TextBox1") as TextBox;
    tb.Text=......
      

  5.   

    FindControl 是比较推崇的办法。