i.Text是不能转换为整数的一个值.

解决方案 »

  1.   

    int id = Int32.Parse(i.Text.ToString());
    -------
    i.Text就是字符串类型了,没有必要再去ToString()了.
      

  2.   

    为了使用上的保险性,你可以使用Int.TryParse来执行转换数字:int id = -1;if (!int.TryParse(i.Text, out id))
    {
        //没有转换成功!
    }
      

  3.   

    先设GridView的DataKeyNames属性:GridView1.DataKeyNames = new string[] { "ID" };
    其中ID是表的int型主键
    然后:
    int id = Convert.ToInt32(this.GridView1.DataKeys[index].Value);
      

  4.   

    protected void GridView1_RowUpdated(object sender, GridViewUpdatedEventArgs e)
        {
          }还有就是GridView1_RowUpdating  不更新,,是不是必须用RowUpdated,,怎么用?ID是从数据中取出来的,
     Snowdust(雪尘) ( ) 信誉:100    Blog   加为好友  2007-04-16 15:04:05  得分: 0  
     
     
       先设GridView的DataKeyNames属性:GridView1.DataKeyNames = new string[] { "ID" };
    其中ID是表的int型主键
    然后:
    int id = Convert.ToInt32(this.GridView1.DataKeys[index].Value);
      
     这个也可以吗,俺没用过个方法.
      

  5.   

    在GridView1中Label1的值可能是空或Label1不是数字。
    在这里要做Check,判断是数字的情况下再int id = Int32.Parse(i.Text.ToString());
      

  6.   

    //删除
        protected void Greedzhao_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            String delsql = "delete from get_zhaoshang_ceshi where id='"+Greedzhao.DataKeys[e.RowIndex].Value.ToString()+"'";
            SqlConnection sqlconn = conn.creatconn();
            sqlconn.Open();
            SqlCommand cmd = new SqlCommand(delsql, sqlconn);
            cmd.ExecuteNonQuery();
            this.databind();
            sqlconn.Close();
        }
        //取消
        protected void Greedzhao_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            Greedzhao.EditIndex = -1;
            this.databind();
        }
        //更新
        protected void Greedzhao_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            string updatesql = "update get_zhaoshang_ceshi set names='"
                 + ((TextBox)(Greedzhao.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim() + "',company='"
                 + ((TextBox)(Greedzhao.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString().Trim() + "',bigkind='"
                 + ((TextBox)(Greedzhao.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim() + "',kind='"
                 + ((TextBox)(Greedzhao.Rows[e.RowIndex].Cells[4].Controls[0])).Text.ToString().Trim() + "' where id='"
                 + Greedzhao.DataKeys[e.RowIndex].Value.ToString() + "'";
            //Response.Write(updatesql);
            //Response.End();
            SqlConnection sqlconn = conn.creatconn();
            sqlconn.Open();
            SqlCommand updatecmd = new SqlCommand(updatesql, sqlconn);
            updatecmd.ExecuteNonQuery();
            this.databind();
            sqlconn.Close();    }