using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
string sqlstr = "Data Source=192.168.0.98;Database=lbs_Test;Uid=sa;Pwd=1";
SqlConnection sqlconn;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.bind();
}
}
protected void GridView1_RowDeleted(object sender, GridViewDeletedEventArgs e)
{
try
{
string str = "delete from Region where data='" + GridView1.DataKeys[e.AffectedRows].Value + "'";
sqlconn = new SqlConnection(sqlstr);
sqlconn.Open();
SqlCommand sqlcom = new SqlCommand(str, sqlconn);
sqlcom.ExecuteNonQuery();
sqlconn.Close();
//this.bind();
}
catch
{
Response.Write("<script>alert('不能删除系统表中自带的字段')</script>");
}
}
}请问我应该怎么改,改在那里,谢谢
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
string sqlstr = "Data Source=192.168.0.98;Database=lbs_Test;Uid=sa;Pwd=1";
SqlConnection sqlconn;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.bind();
}
}
protected void GridView1_RowDeleted(object sender, GridViewDeletedEventArgs e)
{
try
{
string str = "delete from Region where data='" + GridView1.DataKeys[e.AffectedRows].Value + "'";
sqlconn = new SqlConnection(sqlstr);
sqlconn.Open();
SqlCommand sqlcom = new SqlCommand(str, sqlconn);
sqlcom.ExecuteNonQuery();
sqlconn.Close();
//this.bind();
}
catch
{
Response.Write("<script>alert('不能删除系统表中自带的字段')</script>");
}
}
}请问我应该怎么改,改在那里,谢谢
解决方案 »
- WPF中使用WebClient 向win7 上传文件
- jquery easy-ui 在xp 下IE8 下tabs的tab的title不显示
- 线程的LOCK使用问题
- c# sortedlist 排序
- c#菜单的改动问题,急求解决,谢谢
- 有谁能解释下DateSet是怎么实现的么?(工作原理)
- 关于C#写的移动设备程序问题
- 怎样才能获得窗口中有焦点控件的句柄
- 有高手吗?使用泛型类的集合SortedDictionary<string, T> 存储某种类型的对象,当取到不存在的键值如何返回呢?
- C#怎样让窗口标题图片进行转动?
- c#如何实际一个方法的间隔循环执行?
- 在知道DataTable某一列数据的情况下,如何得到这个数据的行索引?
bind(); 写个吧
这个方法呢?
楼主是想把数据绑定到控件吧。那也只有DataBind方法。拷贝别人代码也拷齐全啊……
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GridView1.DataBind();
}
}
吧!要不就是自己写了个绑定GridView1的方法bind(),然后在需要的地方调用!