我有这段代码:
if (e.CommandName == "Comment")
{
SqlConnection scn = new SqlConnection(ClsPublic.GetConnectionString());
SqlCommand scm = new SqlCommand("UPDATE tblImages SET fComment = @fComment WHERE (fId=@fId)", scn);
string mytext = "";
foreach (GridViewRow row in GVPictures.Rows)
{
mytext = ((RadioButtonList)row.FindControl("RBComment")).SelectedItem.Text;
}
scm.Parameters.AddWithValue("@fComment", mytext);
scm.Parameters.AddWithValue("@fId", e.CommandArgument);
scn.Open();
scm.ExecuteNonQuery();
scn.Close();
}
但是,此代码返回最后一行的值,而不是我选择的行。我能做什么? 如何获得选定的行值?
答案 0 :(得分:0)
“((单选按钮列表)e.SelectedRow.FindControl( ”RBComment“))SelectedValue.Text。 要么 ((单选按钮列表)e.Row.FindControl( “RBComment”))SelectedValue.Text;'