因此,对于一个项目,我试图从数据库中检索一个值,并在单击编辑按钮时将其存储在占位符中。我已经尝试了很多方法来让它工作,但它只返回第一行第一列的值。我希望它从我选择编辑的行中返回值。到目前为止,这就是我在后面的代码中所拥有的。
protected void grdEditPersonnel_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Edit")
{
//sets the value of the row selected for possible use??
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow selectedRow = grdEditPersonnel.Rows[index];
try
{
OleDbConnection connection = new OleDbConnection(ConfigurationManager.ConnectionStrings["RiskManager_DBConnectionString"].ConnectionString);
OleDbCommand command = new OleDbCommand("SELECT [ID] FROM [tblProjects]", connection);
connection.Open();
OleDbDataReader reader = command.ExecuteReader(CommandBehavior.SingleRow);
while (reader.Read())
{
//sends the value of the ID to the Project ID Place Holder
Session["ProjIDPH"] = reader.IsDBNull(reader.GetOrdinal("ID")) ? null :
reader["ID"].ToString();
}
reader.Close();
//Redirects user to the Add Project page
Response.Redirect("frmProjects.aspx");
}
catch
{
}
}
}