|
I added a System.Web.UI.WebControls.Button to the records of each day in the DataGrid. After binding the data set, when I press the button in the record, only the current record is displayed. I write as follows Yes, but it can't be realized, how can I change it, thank you!
//Code when the page loads
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();
}
//Error code
protected void del_Click(object sender, EventArgs e)
{
FDataSet.Reset();
//The main reason is that the following is wrong, but I don't know how to get the DataKeys value of the current record.
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();
} |
|