((TextBox)e.Item.Cells[n].FindControl("TextBox1")).Text

解决方案 »

  1.   

    谢谢你多次解决我的问题,
    但是这样有个问题,我在这个TEXTBOX输入的值并没有马上绑定,
    ((TextBox)e.Item.Cells[n].FindControl("TextBox1")).Text是以前的值,
    就是说我想改变TEXTBOX的值,并且马上绑定到新值
    有什么好办法吗?
      

  2.   

    you must be doing something wrong, tryif (!IsPostBack)
    {
    //binding your controls using some data source
    }
      

  3.   

    我用e.Item.Cells[3].FindControl("TextBox1").DataBind();好象不行
      

  4.   

    no, you misunderstood me, show your code
      

  5.   

    在ASPX中
    <asp:TemplateColumn HeaderText="数量">
    <HeaderStyle Width="50px"></HeaderStyle>
    <ItemTemplate>
    <asp:TextBox Runat="server" Width="40"  Text='<%# DataBinder.Eval(Container.DataItem, "GoodsCount") %>' ID="Textbox1" >
    </asp:TextBox>
    </ItemTemplate>
    </asp:TemplateColumn><asp:TemplateColumn HeaderText="更新">
    <HeaderStyle Width="50px"></HeaderStyle>
    <ItemTemplate>
    <asp:LinkButton Runat="server" CommandName="update" Text="更新" ID="Linkbutton1"></asp:LinkButton>
    </ItemTemplate>
    </asp:TemplateColumn>
    在CS文件中
    public void ItemCommand(object sender, DataGridCommandEventArgs e)
    {
    if(e.CommandName=="update")
    {

    ((cart)((ArrayList)Session["cart"][e.Item.ItemIndex]).GoodsCount=Convert.ToInt32(((TextBox)e.Item.Cells[3].FindControl("TextBox1")).Text);
    }
    }我把DATAVIEW是一个数组(ArrayList)Session["cart"],
    就是我想在’数量‘这个TEXTBOX中输入新的值,然后在更新按钮中更新数量,就把输入的值重新写到这个数组中
    麻烦你给看一下了
      

  6.   

    where is your Page_Load? where did you do your DataGrid.DataBind()?
      

  7.   

    那里面我绑定了啊
    private void Page_Load(object sender, System.EventArgs e)
    {
    DataGrid1.DataSource=(ArrayList)Session["cart"];
    DataGrid1.DataBind();
    }
      

  8.   

    you are doing the data binding every time the page is loaded, that is why you have the old value for the textbox, tryprivate void Page_Load(object sender, System.EventArgs e)
    {
      if (!IsPostBack)
      {
            DataGrid1.DataSource=(ArrayList)Session["cart"];
            DataGrid1.DataBind();
       }
    }