|
我在DataGrid中每天行记录中都加了一个System.Web.UI.WebControls.Button,绑定数据集后,当我一按记录中的按纽,就只显示当条记录,我是下面这样写的,但是实现不了,请问要怎样改一下,谢谢!
//网页加载时的代码
protected void Page_Load(object sender, EventArgs e)
{
string FSQLStr = " select * from T_NoteBook ";
System.Data.SqlClient.SqlDataAdapter FsqlDataAdapter = new System.Data.SqlClient.SqlDataAdapter(FSQLStr, Fconnection);
FsqlDataAdapter.Fill(FDataSet,"T_NoteBook");
DataGrid1.DataSource = FDataSet.Tables["T_NoteBook"].DefaultView;
DataGrid1.DataKeyField = "FID";
DataGrid1.DataBind();
}
//出错代码
protected void del_Click(object sender, EventArgs e)
{
FDataSet.Reset();
//主要就是下面这条错了,但是我不知道要怎么样才能获到当前记录的DataKeys值。
System.Web.UI.WebControls.DataGridCommandEventArgs E1 = (System.Web.UI.WebControls.DataGridCommandEventArgs)e;
string FID = (string)(DataGrid1.DataKeys[E1.Item.ItemIndex]);
string sqlstr = " select * from T_NoteBook where FID = " + FID;
System.Data.SqlClient.SqlDataAdapter FsqlDataAdapter = new System.Data.SqlClient.SqlDataAdapter(sqlstr, Fconnection);
FsqlDataAdapter.Fill(FDataSet, "T_NoteBook");
DataGrid1.DataSource = FDataSet.Tables["T_NoteBook"].DefaultView;
DataGrid1.DataKeyField = "FID";
DataGrid1.DataBind();
} |
|