i.Text是不能转换为整数的一个值.
解决方案 »
- winfrom实现qq聊天
- 用户控件页面(listview+ObjectDataSource) session值丢失
- BindingSource.Filter = "DateDiff(yyyy, purchaseTime, getdate()) = 0" 时出现异常“表达式包含未定义的函数调用 DateDiff()”
- 如何将richtextbox中的内容转换为字节数组?急急!!
- 为什么我的ListBox选来选去SelectedIndex都是等于-1???????
- ==打印问题求救(winform)==
- DataGrid列标题栏的问题
- 初学C#,感觉做出的桌面程序的界面比较难看,大家怎么解决的?
- vs能跟踪到函数的返回值吗?
- c#真的会替代c++吗?谁能列出c#强于c++的地方?
- .net中Web页面中如何让弹出窗口和Response.Redirect("FST_Management2.aspx")一起使用?
- 请教个C#问题.高手进来.50分.解决就结分!~~~~~
-------
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(); }