int id = Int32.Parse(i.Text.ToString()); ------- i.Text就是字符串类型了,没有必要再去ToString()了.
为了使用上的保险性,你可以使用Int.TryParse来执行转换数字:int id = -1;if (!int.TryParse(i.Text, out id)) { //没有转换成功! }
先设GridView的DataKeyNames属性:GridView1.DataKeyNames = new string[] { "ID" }; 其中ID是表的int型主键 然后: int id = Convert.ToInt32(this.GridView1.DataKeys[index].Value);
先设GridView的DataKeyNames属性:GridView1.DataKeyNames = new string[] { "ID" }; 其中ID是表的int型主键 然后: int id = Convert.ToInt32(this.GridView1.DataKeys[index].Value);
这个也可以吗,俺没用过个方法.
在GridView1中Label1的值可能是空或Label1不是数字。 在这里要做Check,判断是数字的情况下再int id = Int32.Parse(i.Text.ToString());
-------
i.Text就是字符串类型了,没有必要再去ToString()了.
{
//没有转换成功!
}
其中ID是表的int型主键
然后:
int id = Convert.ToInt32(this.GridView1.DataKeys[index].Value);
{
}还有就是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);
这个也可以吗,俺没用过个方法.
在这里要做Check,判断是数字的情况下再int id = Int32.Parse(i.Text.ToString());
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(); }