Я хотел бы получить DeptID
из выбранной строки. Я связываю вид сетки следующим образом
private void PopulateGridView()
{
SqlConnection myConnection = new SqlConnection(ConnectionString);
SqlDataAdapter ad = new SqlDataAdapter("SELECT * FROM tblEmp", myConnection);
DataSet ds = new DataSet();
ad.Fill(ds);
dynamicGrid.DataSource = ds;
dynamicGrid.DataBind();
}
Для применения цвета к выбранной строке я пишу следующим образом
protected void dynamicGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
if ((e.Row.RowType == DataControlRowType.DataRow))
{
e.Row.Attributes.Add("onclick", "javascript:ChangeRowColor('" + e.Row.ClientID + "')");
// e.Row.Attributes.Add("onclick", "location='Default9.aspx?id=" + e.Row.Cells[0].Text + "'");
//e.Row.Attributes["onClick"] = "location.href='Default8.aspx?id=" + DataBinder.Eval(e.Row.DataItem, "id") + "'";
}
}
Сценарий, который я использовал, выглядит следующим образом
<script type="text/javascript">
//variable that will store the id of the last clicked row
var previousRow;
function ChangeRowColor(row)
{
//If last clicked row and the current clicked row are same
if (previousRow == row)
return;//do nothing
//If there is row clicked earlier
else if (previousRow != null)
document.getElementById(previousRow).style.backgroundColor = "#ffffff";//change the color of the previous row back to white
document.getElementById(row).style.backgroundColor = "#ffffda";//change the color of the current row to light yellow
window.open("Default9.aspx");
//assign the current row id to the previous row id for next row to be clicked
previousRow = row;
}
</script>
Теперь я хотел бы получить deptid
определенной строки, когда пользователь выбирает строку, может ли кто-нибудь мне помочь, а также как я могу передать это на следующую строку в скрипте, который я использовал
**window.open("Default9.aspx");**