如果第9列應該是Cells[8]吧
你把出錯信息貼出來看一下吧

解决方案 »

  1.   

    ((TextBox)DataGrid.Cells[2].FindControl("TextBox1")).Text;
      

  2.   

    Html:  <asp:BoundColumn DataField="GiftShipperSL" HeaderText="发货人"></asp:BoundColumn>
    <asp:BoundColumn DataField="GiftConsignee" HeaderText="收货人"></asp:BoundColumn>
    <asp:BoundColumn DataField="ShipmentDate" HeaderText="日期" DataFormatString="{0:yyyy-MM-dd}"></asp:BoundColumn>
    <asp:EditCommandColumn ButtonType="PushButton" UpdateText="更新" CancelText="取消" EditText="编辑"></asp:EditCommandColumn>
    <asp:ButtonColumn Text="删除" ButtonType="PushButton" CommandName="Delete"></asp:ButtonColumn>CS:  string  strGiftShipperSL=((TextBox)e.Item.Cells[7].Controls[0]).Text.ToString();  
    string  strGiftConsignee=((TextBox)e.Item.Cells[8].Controls[0]).Text.ToString(); 
    //              string strDate=((TextBox)e.Item.Cells[9].Controls[0]).Text.ToString();  
    // TextBox strdate=((TextBox)e.Item.Cells[9].Controls[0]);
    string  strdate=((TextBox)e.Item.FindControl("ShipmentDate")).Text;现在发现就是取日期的时候有问题 下面的sql就会有问题
      

  3.   

    把ItemDataBond事件裡的代碼貼出來
      

  4.   

    下面是update代码 第九列放的是日期
    protected void DataGrid1_Update(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
    {
    try
    {
    string  conStr = ConfigurationSettings.AppSettings["connString"];
    string  strid = e.Item.Cells[1].Text.ToString();
    // string  strid = DataGrid1.DataKeys[e.Item.ItemIndex].ToString();
    string  strdb = e.Item.Cells[2].Text.ToString();
    string  strLayout = e.Item.Cells[3].Text.ToString();
    string  strGiftSale = e.Item.Cells[4].Text.ToString();
                    string  strGiftName = e.Item.Cells[5].Text.ToString();
                    string  strGiftNum = ((TextBox)e.Item.Cells[6].Controls[0]).Text.ToString(); 
    string  strGiftShipperSL=((TextBox)e.Item.Cells[7].Controls[0]).Text.ToString();  
    string  strGiftConsignee=((TextBox)e.Item.Cells[8].Controls[0]).Text.ToString(); 
    //              string strDate=((TextBox)e.Item.Cells[9].Controls[0]).Text.ToString();  
    // TextBox strdate=((TextBox)e.Item.Cells[9].Controls[0]);
    string  strdate=((TextBox)e.Item.FindControl("ShipmentDate")).Text; string  updateCmd="UPDATE Gift_shipment set GiftName='"+strGiftName+"',LayoutName='"+strLayout+"',GiftSale='"+strGiftSale+"',ShipmentDate='"+strDate+"',GiftNum='"+strGiftNum+"',GiftShipperSL='"+strGiftShipperSL+"',GiftConsignee='"+strGiftConsignee+"' where  id ='"+strid+"'";

    SqlConnection con=new SqlConnection(conStr);
    SqlCommand   myCommand=new  SqlCommand(updateCmd,con);   
    myCommand.Connection.Open();   
    myCommand.ExecuteNonQuery();   
    DataGrid1.EditItemIndex=-1;   
    GetSqlData(); }
    catch
    {
    Response.Write("<script>alert('修改失败!')</script>");
    }
      

  5.   

    晕,你日期不进行转换怎么存储到数据表。
    一个是time型,一个是字符串型。
      

  6.   

    DateTime MyDate;
    MyDate = Convert.ToDateTime(txtInput.Text);
      

  7.   

    现在的问题是重Datagrid取值就有问题
      

  8.   

    string strDate=((TextBox)e.Item.Cells[9].Controls[0]).Text.ToString();   这样取好象不行呀
      

  9.   

    string strDate=((TextBox)e.Item.Cells[8].FindControl("TextBox1")).Text.ToString();
      

  10.   

    对,第九烈应该是Cells[8],你把9换成8应该就没问题。
      

  11.   

    换了都不行啊! 我直接给StrDate赋了植就可以写入数据库了 上面的写法不行