急!有关DataGrid控件的属性问题,如马上回答直接再加

来源:百度知道 编辑:UC知道 时间:2024/05/14 06:06:19
要做一个用户管理的服务器端的程序,想用DataGrid控件来显示
现在我想做这样一个功能:
选择一行(就是一横行,不是字段,也不知道叫什么:P),然后点击删除健删除
如果用SQL删除,但是SQL搜索的话,要定义出字段和哪一行被选中阿,对吧?我不知道那被选中的行的属性是什么(我是指DataGrid. 后面的那串英文)请问有人知道吗?
或者谁有另外的实现的方法也可

用事件来做
在private void InitializeComponent(){}中写上this.DataGrid1.CancelCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_CancelCommand);

然后写DataGrid1_CancelCommand事件的代码,如下
private void DataGrid1_DETELECommand(object sander ,DataGridCommandEventArgs e)
{
SqlConnection sqlcon=new SqlConnection("server=.;uid=用户;pwd=密码;database=数据库");
sqlcon.open();//连接数据库
SqlCommand sqlcmd=new SqlCommand("DETELE 表名 WHERE 主键列="+e.Item.Cell[0].Text,sqlcon);
sqlcmd.ExecuteNonQuery();//执行SQL语句
DataGrid1.EditItemIndex=-1;//编辑的项的索引。默认值为 -1,指示在 DataGrid 控件中不编辑任何项。
BindDataGrid();//自定义函数重新绑定DataGrid
}

//重新绑定的函数就不解释了吧
pprivate void BindDataGrid()
{
SqlDataAdapter dt=new SqlDataAdapter(selectString,sqlcon);
DataSet ds=new DataSet();
dt.Fill(ds);
DataGrid1.DataSource=ds.Tables[0].DefaultView;
DataGrid1.DataBind();
}<